Originally posted by priti manas duddilla:
Why doestn't the Catch block in Main() execute?
and how come System.out.print(�end �); executed?
Hi Priti,
The main() catch block doesn't execute because the exception is not re-thrown from the test() method. The catch() block in the test() method catches the exception thrown by the test() method. If you want the method that calls test() to react to exceptions, you need to throw it again. You can do this in a few different ways.
1: you can add a line inside the catch block at line 16 to throw the exception again. (Add it after the System.out.print() line.)
2: you can add a finally block after line 16 with a throw in it. In this case, the finally() block will be called from the catch() block at 16, *NOT* the try() block at 12.
3: you can add a throw outside of the try/catch block between lines 16 and 17. Execution of the method doesn't stop with the catch() block unless you return or exit within it.
Hope this helps...
Aloha,
Doug