I know what are the output. But question is what is the explanation of that out put.
public class LongExp{
LongExp() throws Exception{
LongExp.start();
}
public static void start()throws RuntimeException{
throw new IllegalMonitorStateException();
}
public static void main(String args[]) throws Throwable{
try{
try{
try{
new LongExp();
} catch(Throwable t){
System.out.println("catch(Throwable t) 1" );
throw t;
}
}catch(Throwable t){
System.out.println("catch(Throwable t) 2" );
if (t instanceof IllegalMonitorStateException){
System.out.println("(t instanceof IllegalMonitorStateException)" );
throw (RuntimeException)t;
}else{
System.out.println("else (t instanceof IllegalMonitorStateException)" );
throw (IllegalMonitorStateException)t;
}
}
}catch(IllegalMonitorStateException e){
System.out.println("a" );
}catch(RuntimeException e){
System.out.println("b" );
}catch(Exception e){
System.out.println("c" );
}catch(Throwable e){
System.out.println("d" );
}
}
}
This are the output
catch(Throwable t) 1
catch(Throwable t) 2
(t instanceof IllegalMonitorStateException)
a
My explanation what ever is being propagated by the type conversion, It was just the change of the reference but not the instance type of that exception-object. That is why at the end It caught the IllegalMonitorStateException .
Am I correct ?
EDIT:TYPOS;