-
Notifications
You must be signed in to change notification settings - Fork 16
/
trycatch-001.sfu
206 lines (201 loc) · 3.4 KB
/
trycatch-001.sfu
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
title: Try/Catch tests
author: Joshua Thijssen <joshua@saffire-lang.org>
**********
import io;
try {
foo.bar();
} catch (exception e) {
io.print("caught\n");
} finally {
io.print("finally\n");
}
====
caught
finally
@@@@
import io;
try {
foo.bar();
} catch (attributeException e) {
io.print("attribute\n");
} catch (indexException e) {
io.print("index\n");
} catch (exception e) {
io.print("exception\n");
}
====
attribute
@@@@
// Only try, no catch
try {
}
====
Error in line 5: syntax error, unexpected end of file, expecting T_CATCH
@@@@
// non-compound statement
try a catch (Exception e) b;
====
Error in line 3: syntax error, unexpected T_IDENTIFIER, expecting '{'
@@@@
// No typehint
try {
a=1;
} catch (e) {
}
====
Error in line 5: syntax error, unexpected ')', expecting T_IDENTIFIER
@@@@
// Catch-all
try {
a=1;
} catch () {
}
====
Error in line 5: syntax error, unexpected ')', expecting T_IDENTIFIER
@@@@
// Single catch
catch (Exception e) {
}
====
Error in line 3: syntax error, unexpected T_CATCH, expecting end of file
@@@@
// Only a try and finally
try {
} finally {
}
====
Error: line 3: syntax error, unexpected T_FINALLY, expecting T_CATCH
@@@@
// Pass finally
import io;
try {
io.print("try\n");
} catch (exception e) {
io.print("exception\n");
} finally {
io.print("finally\n");
}
====
try
finally
@@@@@@
// Return in try
import io;
class foo {
public method bar() {
try {
io.print("try\n");
return "1";
} catch (exception e) {
io.print("exception\n");
return "2";
} finally {
io.print("finally\n");
}
}
}
f = foo();
io.print(f.bar(),"\n");
====
try
finally
1
@@@@@@
// Return in catch
import io;
class foo {
public method bar() {
try {
io.print("try\n");
foo.notexisting();
return "1";
} catch (exception e) {
io.print("exception\n");
return "2";
} finally {
io.print("finally\n");
}
return "4";
}
}
f = foo();
io.print(f.bar(),"\n");
====
try
exception
finally
2
@@@@@@
// Return in finally
import io;
class foo {
public method bar() {
try {
io.print("try\n");
return "1";
} catch (exception e) {
io.print("exception\n");
return "2";
} finally {
io.print("finally\n");
return "3";
}
}
}
f = foo();
io.print(f.bar(),"\n");
====
try
finally
3
@@@@@@
// Double exception
import io;
try {
io.print("try1\n");
foo.bar();
io.print("not executed\n");
} catch (exception e) {
io.print("exception1\n");
try {
io.print("try2\n");
foo.bar();
io.print("not executed\n");
} catch (exception e) {
io.print("exception2\n");
} finally {
io.print("finally2\n");
}
} finally {
io.print("finally1\n");
}
====
try1
exception1
try2
exception2
finally2
finally1
@@@@@@
// Return in try should not continue, but only do finally
import io;
class foo {
public method bar() {
try {
io.print("try\n");
return "1";
io.print("This should not be printed!\n");
} catch (exception e) {
io.print("exception\n");
return "2";
} finally {
io.print("finally\n");
}
}
}
f = foo();
io.print(f.bar(),"\n");
====
try
finally
1