Hey there! any question in your mind? Ask It Now!.

Popular Categories





Exact use of finally in Java ?

0 votes
62 views
asked in Programming by nishant (380 points)
I am returning false in catch block and I have used finally ,will finally block be called?
lets say: 
try {  
    something();  
    return true;  
}  
catch (Exception e) {   
    return false;  
}  
finally {  
    System.out.println("finally called");
}
 
in this case if result is true and when it false when the finally block will be called?
Please elaborate if you know it. Thanks for help!

1 Answer

+3 votes
answered by Kaperly (1,610 points)
selected by nishant
 
Best answer
Hey Nishant , I would like to tell you that here according to your code finally will be called.
finally block we use for the default statement. We mostly use it in connection of SQL we use finally to close the connection at last weather a exception has come some how but connection should be closed, So we use finally their.
if you want to escape finally for any particulate condition so you can use System.exit() .

one more case in which it wont be called when your JVM crashes first.

I hope you got my point.
commented by nishant (380 points)
Thanks For explanation ! I got your point.
commented by Eathen (1,930 points)
hey @kaperly i also agree with your point. its the actual process of finally.

Related Questions

+2 votes
1 answer 205 views
+5 votes
2 answers 61 views
0 votes
0 answers 56 views
+8 votes
2 answers 106 views
0 votes
0 answers 57 views
0 votes
0 answers 147 views
asked in Programming by vimal jain
0 votes
0 answers 71 views
0 votes
1 answer 115 views
+1 vote
1 answer 776 views
+3 votes
1 answer 643 views

Not a Member yet?

Ask to Folks Login

My Account
1071 Folks are online
69 members and 1002 guest online
Your feedback is highly appreciated