forked from kilim/kilim
/
ExCatch.java
executable file
·166 lines (150 loc) · 3.98 KB
/
ExCatch.java
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
package kilim.test.ex;
import kilim.Pausable;
import kilim.Task;
public class ExCatch extends ExYieldBase {
public ExCatch(int test) {
testCase = test;
}
/*
public void execute() throws pausable {
if (testCase == 3) {
doPause = false;
tryCatchFinally();
}
}
*/
public void execute() throws Pausable {
doPause = false;
test();
doPause = true;
test();
}
private void test() throws Pausable {
switch(testCase) {
case 0: normalCatch(); break;
case 1: pausableCatch(); break;
case 2: nestedPausableCatch(); break;
case 3: tryCatchFinally(); break;
case 4: pausableBeforeCatch(); break;
default: throw new IllegalStateException("Unknown test case: " + testCase);
}
}
void normalCatch() throws Pausable {
double d = fd;
String[][] sa = fa;
String s = fs;
try {
pausable(d);
} catch (ExException eye) {
String es = eye.getMessage();
verify(es);
s = es;
}
verify(d);
verify(sa);
verify(s);
}
void pausableCatch() throws Pausable {
double d = fd;
String s = fs;
String[][] sa = fa;
long l = fl;
try {
pausable(d);
// throw new ExException("10");
} catch (ExException eye) {
String es = eye.getMessage();
if (doPause) {
Task.sleep(50);
}
verify(es);
s = es;
}
verify(d);
verify(sa);
verify(s);
verify(l);
}
// Issue#6 on github. A pausable block before the catch block.
void pausableBeforeCatch() throws Pausable {
int foo = 0;
Task.sleep(1);
if (foo != 0) throw new RuntimeException("Expected 0");
foo = 1;
Task.sleep(1);
if (foo != 1) throw new RuntimeException("Expected 1");
foo = 2;
Task.sleep(1);
if (foo != 2) throw new RuntimeException("Expected 2");
try {
foo = 3;
throwEx();
} catch (Throwable t) {
if (foo != 3) throw new RuntimeException("Expected 3");
}
}
private static void throwEx() throws Pausable {
Task.sleep(1);
throw new RuntimeException();
}
void tryCatchFinally() throws Pausable {
short sh = fsh;
String s = fs;
double d = fd;
long l = fl;
try {
try {
pausable(d);
// throw new ExException("10");
} catch (ExException eye) {
if (doPause) {
Task.sleep(50);
}
throw new Exception("");
} finally {
if (doPause) {
Task.sleep(50);
}
}
} catch (Exception e) {
}
verify(d);
verify(sh);
verify(s);
verify(l);
}
void nestedPausableCatch() throws Pausable {
double d = fd;
String s = fs;
String[][] sa = fa;
long l = fl;
try {
throw new ExException("10");
} catch (final ExException eye) {
String es = null;;
try {
throw new ExException("10");
} catch (Exception e) {
es = eye.getMessage();
verify(es);
es = e.getMessage();
if (doPause) {
Task.sleep(50);
}
}
verify(es);
s = es;
}
verify(d);
verify(sa);
verify(s);
verify(l);
}
private void pausable(double d) throws ExException, Pausable {
if (doPause) {
Task.sleep(50);
}
verify(d);
throw new ExException("10");
}
}