Hi folks 31. Consider the code below: void myMethod() { try { fragile(); } catch( NullPointerException npex ) { System.out.println( "NullPointerException thrown " ); } catch( Exception ex ) { System.out.println( "Exception thrown " ); } finally { System.out.println( "Done with exceptions " ); } System.out.println( "myMethod is done" ); } What is printed to standard output if fragile() throws an IllegalArgumentException? a) "NullPointerException thrown" b) "Exception thrown" c) "Done with exceptions" d) "myMethod is done" e) Nothing is printed According to me the answer should be.. b,c. But the answers in MindQ site are b,c,d. I am bit confused here. Please help Ranjeeta
Hello Dear This is like this in the example IllegalArgumentException thrown by the method fragile() is cought in the catch block(which prints"Exception thrown"), than the finally block is executed(results in printing "Done with exceptions" Now since the exception thrown by the method fragile() is caught by the try & catch block(though not immediate catch block but by the successive catch block)program does not terminates,but it follows the steps bellow the method so resulting in printing "myMethod is done" d will not have been option had the exception thrown is not caught & there by terminating the program. lokesh mahajan
Hi Lokesh thanks a lot for your explanation. I understand it now, that caught exceptions would not terminate the program but uncaught would. I think overdoing creates more confusion.. I am realising this, day by day getting more Ranjeeta