Problem : I think the output should be : An exception is thrown and the exception message thrown from first catch is diplayed with the exception stack trace,because of the following reasoning:
When finally block is returning ,it is returning to the JVM which i think is the default Exception Handler,so stack trace should be printed.
Please sort out this..
Thanx [ August 24, 2004: Message edited by: Barry Gaunt ]
posted 11 years ago
It's important to remember that the finally block will always be executed, regardless of whether or not an exception was thrown and/or caught. The outcome of the finally block may very well dictate what happens to the first exception (if one was thrown).
For example, if your try block ends abruptly and causes an exception to be thrown, your finally block will execute. If your finally block ends abruptly, due to an exception, the second exception (the one from the finally block) will be thrown and the original exception will be lost.
In your case, you're seeing a similar case. The try block ends abruptly and execution flows through the catch block and into the finally block. The finally block, however, tells the method to return, which causes completion of the method before the exception can be propogated back up to the calling method. In such a case, the exception is basically ignored.