File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
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.
I agree. Here's the link:
subject: Exception handling
jQuery in Action, 3rd edition