This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Exception handling Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Exception handling" Watch "Exception handling" New topic

Exception handling

manasa teja
Ranch Hand

Joined: May 27, 2002
Posts: 325
Is there any exception case to the following statement?
In a try-catch-finally construct, if a finally block is present, then it is guaranteed to be executed.

Corey McGlone
Ranch Hand

Joined: Dec 20, 2001
Posts: 3271
If the program were to terminate prior to that, the finally block would not be exeucted.
Take this example:


SCJP Tipline, etc.
Anthony Villanueva
Ranch Hand

Joined: Mar 22, 2002
Posts: 1055
Also, if an exception is thrown inside the finally block and is not caught within the same scope, the exception will propagate outwards and the finally block will not complete its execution.
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Only if you call System.exit before the flow reaches the finally block.
It is sorta covered in the JavaRanch Style Guide.
subject: Exception handling
Similar Threads
try and catch
Try Catch Finally - Voodoo Question
Execution of finally
exception thrown in finally