Auf eine Frage an Java an der Universität gab es diesen Codeausschnitt:
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();
}
}
}
Ich wurde gebeten, seine Ausgabe zu geben. Ich antwortete 13Exception in thread main MyExc2, aber die richtige Antwort ist 132Exception in thread main MyExc1. Warum ist es das? Ich kann einfach nicht verstehen, wohin es MyExc2geht.