-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathFullConstructors.java
More file actions
58 lines (47 loc) · 1.43 KB
/
FullConstructors.java
File metadata and controls
58 lines (47 loc) · 1.43 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
package exceptions;
/**
* RUN:
* javac exceptions/FullConstructors.java && java exceptions.FullConstructors
* OUTPUT:
* Initiating MyException from f()
* exceptions.MyException
* at exceptions.FullConstructors.f(FullConstructors.java:16)
* at exceptions.FullConstructors.main(FullConstructors.java:27)
*
* Initiating MyException from g()
* exceptions.MyException: Created in g()
* at exceptions.FullConstructors.g(FullConstructors.java:21)
* at exceptions.FullConstructors.main(FullConstructors.java:34)
*/
import java.util.*;
public class FullConstructors {
public static void f() throws MyException {
System.out.println("Initiating MyException from f()");
throw new MyException();
}
public static void g() throws MyException {
System.out.println("Initiating MyException from g()");
throw new MyException("Created in g()");
}
public static void main(String[] args)
{
try {
f();
}
catch (MyException e) {
e.printStackTrace(System.err);
}
try {
g();
}
catch (MyException e) {
e.printStackTrace(System.err);
}
}
}
class MyException extends Exception {
public MyException() {}
public MyException(String msg) {
super(msg);
}
}