if i have a following code
try{
//some code
}catch(Exception e){
//some code
}finally{
}
what happens to the finally block in the following cases
-
if any checked exceptions happen.
-
if System.exit() is called.
-
if any unchecked exceptions happen.
-
if any errors happen.
finallyblock is executed.finallyblock is not executed unless System.exit() throws an Exception, in which case thefinallyblock is executed. (see How does Java’s System.exit() work with try/catch/finally blocks?)finallyblock is executed.finallyblock is executed (depends on the type of error though, if you’re talking about a JVM error, then there’s really no telling what might happen).