In a Java try{} ... catch{} ... finally{} block, code within the finally{} is generally considered \"guaranteed\" to run regardless of what occurs
Testing the finally block in different statement in try block.
public static void main(String [] args){
try{
System.out.println("Before Statement");
/*** Statement ***/
System.out.println("After Statement");
}
catch(Exception e){
}
finally{
System.out.println("Finally is Executed");
}
Statements in which finally block is executed are following:
Thread.currentThread().interrupted();Thread.currentThread().destroy();Thread.currentThread().stop();Thread.sleep(10);Thread.currentThread().interrupt();Runtime.getRuntime().addShutdownHook(Thread.currentThread());Statements in which finally block is not executed are following:
Thread.currentThread().suspend();System.exit(0);Runtime.getRuntime().exit(0);Runtime.getRuntime().halt(0);