Meaningless Drivel is fun!
The moose likes Beginning Java and the fly likes Exception in finally Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Exception in finally" Watch "Exception in finally" New topic

Exception in finally

kiran kumar

Joined: May 24, 2008
Posts: 18
what happens when exception occurs at finally clause?

Thanks & Regards,<br />Bhuvan Samrat.
Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

One of those questions best answered by writing some code and seeing what happens.

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
camilo lopes
Ranch Hand

Joined: Aug 08, 2007
Posts: 202
finally is optional, but you can use for close one file open for example. case you have forget.

one point important that finally only is run.

Brazil - Sun Certified Java Programmer - SCJP 5 About Java - Update every Week.
Guide SCJP - tips that you need know
haripriya vedula

Joined: May 31, 2008
Posts: 24
finally creates a block of code that will be executed after try/catch block is completed. The finally block will execute whether or not exception is thrown..
Eric Daly
Ranch Hand

Joined: Jul 11, 2006
Posts: 143
It's just the same as if you had an exception thrown anywhere else... try it and see. Will you need to handle it? That depends on whether or not it's a checked exception.

Studying for SCJP 6
Bill Shirley
Ranch Hand

Joined: Nov 08, 2007
Posts: 457
Here's an example (yanked out of my code) of the case you are asking about...

(note: i use this as a workaround, not as a standard copy mechanism)

Bill Shirley - bshirley -
if (Posts < 30) JavaRanchFAQ);
I agree. Here's the link:
subject: Exception in finally
It's not a secret anymore!