Does a finally block always get executed in Java?
Asked 07 September, 2021
Viewed 757 times
  • 47
Votes

Considering this code, can I be absolutely sure that the finally block always executes, no matter what something() is?

try {  
    something();  
    return success;  
}  
catch (Exception e) {   
    return failure;  
}  
finally {  
    System.out.println("I don't know if this will get printed out");
}

30 Answer