package testing;
public class ExceptionHandling {
public static void main(String[] args){
try{
int a=10;
int b=0;
int c=a/b;
ExceptionHandling exp = null;
System.out.println(exp);
throw new NullPointerException();
}catch(ArithmeticException e){
System.out.println("arithmetic issue");
throw new ArithmeticException();
}
catch(NullPointerException e){
System.out.println("nullpointer");
}
finally{
System.out.println("exception");
//throw new ArithmeticException();
}
}
}
In console I am getting this:
arithmetic issue
exception
Exception in thread "main" java.lang.ArithmeticException
at testing.ExceptionHandling.main(ExceptionHandling.java:15)
But why it gets printed finally block statement first and then catch block statement? It should print catch block statement first and then finally block statement.