I am trying to understand the flow throwing an exception inside catch.
public static void main(String[] args) {
try
{
throw new IOException();
}
catch(IOException e)
{
System.out.println("catch 1");
throw new ArrayIndexOutOfBoundsException();
}
catch (ArrayIndexOutOfBoundsException e)
{
System.out.println("catch 2");
}
finally {
System.out.println("finally 1");
}
}
}
I am using Java 8 and IntelliJ IDEA 2016. I am seeing a the below 3 lines printed in the IDE console in different order every time I execute. Is there something I am missing here.
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException
at com.boot.config.Test.main(Test.java:17)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
catch 1
finally 1
I don't understand why would the stacktrace is thrown before "catch 1"?