import java.io.*;

public class IOExample {
    
    public static int getPartNumber()
                throws InvalidPartNumberException {
        BufferedReader in = new BufferedReader(
                            new InputStreamReader(System.in));

        System.out.print("Please enter part number: ");
        try {
            
            String line = in.readLine();
            // line should be something like A78930
            
            char ch = line.charAt(0);
            String substr = line.substring(1, 6);
            int val = Integer.parseInt(substr);
            return val;
            
        } catch (IOException e) {
            throw new InvalidPartNumberException("Basic input error");
        } catch (StringIndexOutOfBoundsException e) {
            throw new InvalidPartNumberException("Not enough characters");
        } catch (NumberFormatException e) {
            throw new InvalidPartNumberException("Didn't type a number");
        }
    }
    
    public static void main(String[] args) {
        boolean ok = false;
        while (!ok) {
            try {
                int val = getPartNumber();    
                ok = true;
            } catch (InvalidPartNumberException e) {
                System.out.println(e);
                e.printStackTrace();
            }
        }        
    }    
    
}