Exception Handling Problem Again!

Soldato
Joined
27 Aug 2004
Posts
17,111
Location
Geordieland
Hi guys, Ive got it working properly now bar one thing. Its works fine, but on the first catch I want it to just say 'Exception Caught' but its saying Excpetion Caught and then giving me the exception error anyway.

Code:
public class ExceptionHomework
{
    Scanner scan ;
    int data;
    int slot;
    int[] value;

	boolean done = false;

    public ExceptionHomework()
    {
        scan = new Scanner( System.in );
        data=0;
        slot=0 ;
        value = new int[10];
    }

    public void Data()
    {
    	do
    	{
    		try
    		{
      			System.out.print("Enter the data: ");
      			data = scan.nextInt();
      		}
      		
      		catch (InputMismatchException inm)
			{
		 		System.out.println("Exception error "+inm.toString()+ " caught\n");
			}
			
			try
			{
			    System.out.print("Enter the array index: ");
      			slot = scan.nextInt();
      			value[slot] = data;		
			}

			catch(ArrayIndexOutOfBoundsException oob)
			{
				System.out.println("Exception "+oob.toString()+ " caught\n");
			}
			
		}
		while(!done);
	}
}

Code:
public class ExceptionHomeworkDriver
{
	public static void main ( String [] args)
	{
	     ExceptionHomework exHmwk = new  ExceptionHomework();
	     exHmwk.Data();
	     System.out.println("Good Bye");
	}
}

Can anyone give me a hint as to why its catching the error and then letting it go through the catch.

Cheers for any help.
 
Back
Top Bottom