This week's book giveaway is in the JDBC forum.
We're giving away four copies of Make it so: Java DB Connections & Transactions and have Marcho Behler on-line!
See this thread for details.
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 Make it so: Java DB Connections & Transactions this week in the JDBC forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Exceptions" Watch "Exceptions" New topic


Smitha Ballikar
Ranch Hand

Joined: Aug 02, 2005
Posts: 99

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 }

Mark Spritzler

Joined: Feb 05, 2001
Posts: 17276

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


Perfect World Programming, LLC - iOS Apps
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.
I agree. Here's the link:
subject: Exceptions
It's not a secret anymore!