Hi,
finally will always be executed only exception is that when any of the catch blocks or try block calls system.exit() but consider this code.
public class testfinally{
void
test(int i){
if ( i == 1)
return; // replace this with throw new RuntimeException();
try{
System.out.println("1");
}catch(Exception e){e.printStackTrace();}
finally{System.out.println("in finally");}
}
public static void main(
String[] args){
new testfianlly().test(1);
}
}
even in this case when the if condition is satisfied it simply returns or throw some exception in any of this cases to finally block doesnt execute what is the reason for finally block not being executed.
Thanks