File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Return from finally block

 
tanu dua
Ranch Hand
Posts: 145
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all !



Output : Prints nothing.

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 ]
 
Corey McGlone
Ranch Hand
Posts: 3271
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

I hope that helps,
Corey
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic