-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExceptionTest.java
More file actions
105 lines (81 loc) · 1.93 KB
/
ExceptionTest.java
File metadata and controls
105 lines (81 loc) · 1.93 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/**
* Created by fengqiang on 2017/5/5.
*/
/*
毕老师用电脑上课。
开始思考上课中出现的问题。
比如问题是
电脑蓝屏。
电脑冒烟。
要对问题进行描述,封装成对象。
可是当冒烟发生后,出现讲课进度无法继续。
出现了讲师的问题:课时计划无法完成。
*/
class LanPingException extends Exception{
LanPingException(String message){
super(message);
}
}
class MaoYanException extends Exception{
MaoYanException(String message){
super(message);
}
}
class NoPlanException extends Exception
{
NoPlanException(String msg)
{
super(msg);
}
}
class Computer {
private int status = 3;
public void run() throws LanPingException,MaoYanException{
if (status == 2){
throw new LanPingException("蓝屏了");
}else if(status == 3){
throw new MaoYanException("冒烟了");
}else {
System.out.println("正常运行");
}
}
public void reset(){
status = 1;
System.out.println("重启");
}
}
class Teacher{
private String name;
private Computer cmpt;
public Teacher(String name) {
this.name = name;
cmpt = new Computer();
}
public void prelect() throws NoPlanException{
try {
cmpt.run();
}catch (LanPingException e){
cmpt.reset();
}catch (MaoYanException e){
test();
throw new NoPlanException("wuke"+e.getMessage());
}
}
public void test(){
System.out.println("练习");
}
}
class ExceptionTest {
public static void main(String[] args){
Teacher t = new Teacher("毕老师");
try
{
t.prelect();
}
catch (NoPlanException e)
{
System.out.println(e.toString());
System.out.println("换老师或者放假");
}
}
}