-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDemoException
55 lines (53 loc) · 1.36 KB
/
DemoException
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
package DemoException;
/**
* 对异常的捕捉与处理
*/
class MyException extends Exception{
private int i;
public MyException(){};
public MyException(String msg){
super(msg);
}
public MyException(String msg,int x){
super(msg);
i = x;
}
public int val(){
return i;
}
}
public class DemoException {
public static void a() throws MyException{
System.out.println("a()throw");
throw new MyException();
}
public static void b() throws MyException{
System.out.println("b()throw");
throw new MyException("b()`s exception");
}
public static void c() throws MyException{
System.out.println("c()throw");
throw new MyException("c`s exception",01);
}
public static void main(String[] args) {
try {
a();
}catch (MyException e){
System.out.println(e.getMessage());
System.out.println(e.toString());
}
try {
b();
}catch (MyException e){
System.out.println(e.getMessage());
System.out.println(e.toString());
}
try {
c();
}catch (MyException e){
System.out.println(e.getMessage());
System.out.println(e.toString());
System.out.println("errorcode:"+e.val());
}
}
}