This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Java in General and the fly likes try catch finally sequence Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "try catch finally sequence" Watch "try catch finally sequence" New topic
Author

try catch finally sequence

Shankar Narayana
Ranch Hand

Joined: Jan 08, 2003
Posts: 134
Hi all,

I am very well aware of the situation in which the try, catch and finally work but i have a program code for which i am not able to determine what the sequence is..

Here goes the code:


Now my question is what happens if there is a Sql error in the case 1, will the finally be executed and then the error is caught or only the error is caught without finally.


"Failure is not when you fall down; its only when you fail to get up again."
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

The "finally" is executed before the catch blocks are entered.


[Jess in Action][AskingGoodQuestions]
Shankar Narayana
Ranch Hand

Joined: Jan 08, 2003
Posts: 134
so what happens to the exception, is it caught or left.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

It goes "through" the finally block and is caught.
Ulas Ergin
Ranch Hand

Joined: Oct 10, 2002
Posts: 77
if an exception occurs in the try block of case 1
*first finally block of the try in case 1 will be executed
*exception will be handled by the catch block of the outer try since you have no catch block in the case 1's try
 
Don't get me started about those stupid light bulbs.
 
subject: try catch finally sequence