Answers for "does finally block executed after crash"

1

does finally block executed after crash

///Finally block will be executed even if the catch failes to "catch" the exception.
    public static void main(String[] args) {
        try{
            throw new ArrayIndexOutOfBoundsException();
        }catch(NullPointerException e){
            System.out.println("CATCH BLOCK");
        }finally{
            System.out.println("FINALLY");
        }
    }
    
//output: FINALLY
//Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException
       // at test.main(test.java:4)
Posted by: Guest on December-31-2021
0

where finally block will not be executed

Finally block will not be executed whenever jvm shutdowns. 
If we use system.exit(0) in try statement finally block if present 
will not be executed.
Posted by: Guest on December-01-2020

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language