-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathExtraFeatures.java
More file actions
88 lines (71 loc) · 2.29 KB
/
ExtraFeatures.java
File metadata and controls
88 lines (71 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package exceptions;
/**
* RUN:
* javac exceptions/ExtraFeatures.java && java exceptions.ExtraFeatures
* OUTPUT:
* MyException2 in f()
* exceptions.MyException2: Detailed message: 0 null
* at exceptions.ExtraFeatures.f(ExtraFeatures.java:18)
* at exceptions.ExtraFeatures.main(ExtraFeatures.java:33)
* MyException2 in g()
* exceptions.MyException2: Detailed message: 0 Initiated in g()
* at exceptions.ExtraFeatures.g(ExtraFeatures.java:23)
* at exceptions.ExtraFeatures.main(ExtraFeatures.java:40)
* MyException2 in h()
* exceptions.MyException2: Detailed message: 47 Initiated in h()
* at exceptions.ExtraFeatures.h(ExtraFeatures.java:28)
* at exceptions.ExtraFeatures.main(ExtraFeatures.java:47)
* e.val() = 47
*/
// import java.util.logging.*;
// import java.io.*;
public class ExtraFeatures {
public static void f() throws MyException2 {
System.out.println("MyException2 in f()");
throw new MyException2();
}
public static void g() throws MyException2 {
System.out.println("MyException2 in g()");
throw new MyException2("Initiated in g()");
}
public static void h() throws MyException2 {
System.out.println("MyException2 in h()");
throw new MyException2("Initiated in h()", 47);
}
public static void main(String[] args) {
try {
f();
}
catch (MyException2 e) {
e.printStackTrace(System.out);
}
try {
g();
}
catch (MyException2 e) {
e.printStackTrace(System.out);
}
try {
h();
}
catch (MyException2 e) {
e.printStackTrace(System.out);
System.out.println("e.val() = "+e.val());
}
}
}
class MyException2 extends Exception {
private int x;
public MyException2() {}
public MyException2(String msg) {
super(msg);
}
public MyException2(String msg, int x) {
super(msg);
this.x = x;
}
public int val() { return x; }
public String getMessage() {
return "Detailed message: " + x + " " + super.getMessage();
}
}