RethrowExceptionExmp2

RethrowExceptionExmp2 - throws InputMismatchException...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
h //RethrowExceptionExmp2 / import java.util.*; i public class RethrowExceptionExmp2 { static Scanner console = new Scanner(System.in); public static void main(String[] args) //Line 1 { int number; //Line 2 try //Line 3 { number = getNumber(); //Line 4 System.out.println("Line 5: number = " + number); //Line 5 } catch (InputMismatchException imeRef) //Line 6 { System.out.println("Line 7: Exception " + imeRef.toString()); //Line 7 } } public static int getNumber()
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: throws InputMismatchException //Line 8 { int num; //Line 9 try //Line 10 { System.out.print("Line 11: Enter an " + "integer: "); //Line 11 num = console.nextInt(); //Line 12 System.out.println(); //Line 13 return num; //Line 14 } catch (InputMismatchException imeRef) //Line 15 { System.out.println("Line 16: Exception " + imeRef.toString()); //Line 16 throw new InputMismatchException ("getNumber"); //Line 17 } } }...
View Full Document

Ask a homework question - tutors are online