-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathRethrowNew.java
More file actions
52 lines (44 loc) · 1.55 KB
/
RethrowNew.java
File metadata and controls
52 lines (44 loc) · 1.55 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
package exceptions;
/**
* RUN:
* javac exceptions/RethrowNew.java && java exceptions.RethrowNew
* OUTPUT:
* creating exception from f()
* In inner "try" section: e.printStackTrace()
* exceptions.OneException: thrown from f()
* at exceptions.RethrowNew.f(RethrowNew.java:25)
* at exceptions.RethrowNew.main(RethrowNew.java:31)
* In outer "try" section: e.printStackTrace()
* exceptions.TwoException: thrown from inner "try" section
* at exceptions.RethrowNew.main(RethrowNew.java:36)
*/
// import java.util.logging.*;
// import java.io.*;
public class RethrowNew {
public static void f() throws OneException {
System.out.println("creating exception from f()");
throw new OneException("thrown from f()");
}
public static void main(String[] args) {
try {
try {
f();
}
catch(OneException e) {
System.out.println("In inner \"try\" section: e.printStackTrace() ");
e.printStackTrace(System.out);
throw new TwoException("thrown from inner \"try\" section");
}
}
catch(TwoException e) {
System.out.println("In outer \"try\" section: e.printStackTrace() ");
e.printStackTrace(System.out);
}
}
}
class OneException extends Exception {
public OneException(String s) { super(s); }
}
class TwoException extends Exception {
public TwoException(String s) { super(s); }
}