aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Exceptions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Exceptions" Watch "Exceptions" New topic
Author

Exceptions

Smitha Ballikar
Ranch Hand

Joined: Aug 02, 2005
Posts: 99
Hi,

I just compiled and checked if there is a return statement as first statement in finally block it gives compiler error saying unreachable statement which is fine .If I put a return statement in try block it works fine.What happens if I put return statement in catch block?Is finally block still executed??
Like for Eg:
try{ //code }
catch(){ return; }
finally{ //code }

Regards,
Smitha
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

Yes. Basically the only time finally block isn't run is if there is a System crach our a System.exit() call.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Ryan Kade
Ranch Hand

Joined: Aug 16, 2005
Posts: 69
The finally block will also stop executing if you throw another exception while in the block.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Exceptions