Hi, Consider the following code: 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" ); }
It prints: Exception thrown Done with exceptions myMethod is done Why does it print the last line? I thought finally is called before the method exits...Could someone help me please? Or is it that the rest of the method is executed after handling the exception? Regards, Kapil
Hope this helps. Correct me if I am wrong.<p>Cheers <img src="smile.gif" border="0"> ,<br />Kapil
Vidya Krishnamurthy
Greenhorn
Joined: Mar 27, 2001
Posts: 15
posted
0
If the Exception is caught, the method doesn't terminate and the statements following the finally block gets executed. if the exception is not caught, then the finally block gets executed and the method terminates. In your example, as the exception is caught, the lines following the finally block gets executed. Hope this helps
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.