01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
class AEx extends RuntimeException { AEx(String s) { super(s); } }
class BEx extends AEx { BEx(String s) { super(s); } }
class K {
static { if (true) throw new AEx("AEx z K.static"); }
}
class A {
A(double d) {throw new AEx("AEx z A.A(double)");}
A() { }
A(int i) {throw new BEx("BEx z A.A(int)"); }
void f(int i) {
if (i%2 == 0) throw new BEx("BEx z A.f");
throw new AEx("AEx z A.f");
}
void g() {
try {
try { f(0); }
catch (AEx ae) {ae.printStackTrace();}
}
catch (BEx be) {be.printStackTrace();}
f(1);
}
void h() { g(); }
}
public class tmp {
public static void main(String argd[]) {
try { System.out.println(K.class);
}
catch (Throwable e) {e.printStackTrace(); }
try { new K(); }
catch (Throwable e) {e.printStackTrace(); }
A a;
try {
a = new A(1.5);
System.out.println("A stworzony przez A(double)");
}
catch (AEx ae) {
ae.printStackTrace();
try {
a=new A(1);
System.out.println("A stworzony przez A(int)");
}
catch (AEx ae2) {
ae2.printStackTrace();
a=new A();
System.out.println("A stworzony przez A()");
}
}
a.h();
}
}
W
yjście
java.lang.ExceptionInInitializerError: AEx: AEx z K.static
at K.<clinit>(tmp.java:6)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:115)
at tmp.class$(tmp.java:27)
at tmp.main(tmp.java:29)
java.lang.NoClassDefFoundError
at tmp.main(tmp.java:31)
AEx: AEx z A.A(double)
at A.<init>(tmp.java:10)
at tmp.main(tmp.java:35)
BEx: BEx z A.A(int)
at A.<init>(tmp.java:12)
at tmp.main(tmp.java:41)
A stworzony przez A()
BEx: BEx z A.f
at A.f(tmp.java:14)
at A.g(tmp.java:19)
at A.h(tmp.java:25)
at tmp.main(tmp.java:50)
Exception in thread "main" AEx: AEx z A.f
at A.f(tmp.java:15)
at A.g(tmp.java:23)
at A.h(tmp.java:25)
at tmp.main(tmp.java:50)
Press any key
to continue...