在大学里一个关于Java的问题中,有以下代码片段:
class MyExc1 extends Exception {}
class MyExc2 extends Exception {}
class MyExc3 extends MyExc2 {}
public class C1 {
public static void main(String[] args) throws Exception {
try {
System.out.print(1);
q();
}
catch (Exception i) {
throw new MyExc2();
}
finally {
System.out.print(2);
throw new MyExc1();
}
}
static void q() throws Exception {
try {
throw new MyExc1();
}
catch (Exception y) {
}
finally {
System.out.print(3);
throw new Exception();
}
}
}
我被要求提供其输出。我回答了13Exception in thread main MyExc2
,但是正确答案是132Exception in thread main MyExc1
。为什么会这样呢?我只是不知道MyExc2
去哪里。