0 votes
223 views
in Programming by (440 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!
closed

1 Answer

+3 votes
by (1.6k points)
selected by
 
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.
by (440 points)
Thanks For explanation ! I got your point.
by (1.9k points)
hey @kaperly i also agree with your point. its the actual process of finally.

Not a Member yet?

Ask to Folks Login

My Account

Your feedback is highly appreciated