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) {
            throw new ArrayIndexOutOfBoundsException();
        }catch(NullPointerException e){
            System.out.println("CATCH BLOCK");
//output: FINALLY
//Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException
       // at test.main(

Here is what the above code is Doing:
1. The try block throws an ArrayIndexOutOfBoundsException.
2. The catch block is looking for a NullPointerException.
3. The finally block is executed.
4. The exception is thrown.

Similar Posts