I have developed a program in which the case of return statement either inside try block or catch block the finally block executes at last but when I write system.exit inside try block in this case the finally block not executed but still I want to execute , could you please advise do I need to add Runtime.getRuntime().addShutdownHook
in that case I need to add the code that should be executed in any case , even if system.exit is called. please advise , below is my class
public class Hello {
public static void hello(){
try{
System.out.println("hi");
System.exit(1);
// return;
}catch(RuntimeException e)
{ //return;
}
finally{
System.out.println("finally is still executed at last");
}
}
public static void main(String[] args){
Hello.hello();
}
}