public class Confusing{
public static void main(String[] args){
Confusing cf = new Confusing();
try{
cf.confuse();
}catch(Exception e){
System.out.println("Caught exception: " + e.getMessage());
}
}
public void confuse() throws Exception{
try{
throw new Exception("First Exception");
}catch(Exception e){
throw new Exception("Second Exception");
}finally{
throw new Exception("Third Exception");
}
}
}
Why the result is Caught exception: Third Exception
?
First in try, it throws the First Exception
that is subsequently caught. Then throw the Second Exception
and also in finally Third Exception
. Why only the Third Exception
is sent back to the main?