This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv 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 REST with Spring (video course) this week in the Spring 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.
Don't get me started about those stupid light bulbs.
subject: Exception handling
It's not a secret anymore!