OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 // VMOptions=--optimization-counter-threshold=10 | 4 // VMOptions=--optimization-counter-threshold=10 |
5 | 5 |
6 import "package:expect/expect.dart"; | 6 import "package:expect/expect.dart"; |
7 | 7 |
8 class MyException { } | 8 class MyException {} |
9 | 9 |
10 class MyException1 extends MyException { } | 10 class MyException1 extends MyException {} |
11 | 11 |
12 class MyException2 extends MyException { } | 12 class MyException2 extends MyException {} |
13 | 13 |
14 class TryCatchTest { | 14 class TryCatchTest { |
15 static void test1() { | 15 static void test1() { |
16 var foo = 0; | 16 var foo = 0; |
17 try { | 17 try { |
18 throw new MyException1(); | 18 throw new MyException1(); |
19 } on MyException2 catch (e) { | 19 } on MyException2 catch (e) { |
20 foo = 1; | 20 foo = 1; |
21 } on MyException1 catch (e) { | 21 } on MyException1 catch (e) { |
22 foo = 2; | 22 foo = 2; |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 } on int { | 135 } on int { |
136 e = "i"; | 136 e = "i"; |
137 } | 137 } |
138 Expect.equals("s", e); | 138 Expect.equals("s", e); |
139 } | 139 } |
140 | 140 |
141 static void test10() { | 141 static void test10() { |
142 try { | 142 try { |
143 throw "up"; | 143 throw "up"; |
144 } on String catch (e) { | 144 } on String catch (e) { |
145 var e = 1; // ok, shadows exception variable. | 145 var e = 1; // ok, shadows exception variable. |
146 Expect.equals(1, e); | 146 Expect.equals(1, e); |
147 } | 147 } |
148 } | 148 } |
149 | 149 |
150 static void test11() { | 150 static void test11() { |
151 var e0 = 11; | 151 var e0 = 11; |
152 try { | 152 try { |
153 throw "up"; | 153 throw "up"; |
154 } on int catch (e0) { | 154 } on int catch (e0) { |
155 Expect.fail("unreachable"); | 155 Expect.fail("unreachable"); |
156 } on String catch (e1) { | 156 } on String catch (e1) { |
157 // e0 from the other catch clause is not in scope. | 157 // e0 from the other catch clause is not in scope. |
158 Expect.equals(11, e0); | 158 Expect.equals(11, e0); |
159 } | 159 } |
160 } | 160 } |
161 | 161 |
162 static void test12() { | 162 static void test12() { |
163 const x = const []; | 163 const x = const []; |
164 try { | 164 try { |
165 throw "up"; | 165 throw "up"; |
166 } catch (e) { | 166 } catch (e) { |
167 Expect.equals("up", e); | 167 Expect.equals("up", e); |
168 } on String catch (e) { | 168 } on String catch (e) { |
169 // Compile-time constants in unreachable catch blocks are still | 169 // Compile-time constants in unreachable catch blocks are still |
170 // compiled. | 170 // compiled. |
171 const y = x[0]; // //# 01: compile-time error | 171 const y = x[0]; // //# 01: compile-time error |
172 Expect.fail("unreachable"); | 172 Expect.fail("unreachable"); |
173 } | 173 } |
174 } | 174 } |
175 | |
176 | 175 |
177 static void testMain() { | 176 static void testMain() { |
178 test1(); | 177 test1(); |
179 test2(); | 178 test2(); |
180 test3(); | 179 test3(); |
181 test4(); | 180 test4(); |
182 test5(); | 181 test5(); |
183 test6(); | 182 test6(); |
184 test7(); | 183 test7(); |
185 test8(); | 184 test8(); |
186 test9(); | 185 test9(); |
187 test10(); | 186 test10(); |
188 test11(); | 187 test11(); |
189 test12(); | 188 test12(); |
190 } | 189 } |
191 } | 190 } |
192 | 191 |
193 main() { | 192 main() { |
194 for (var i = 0; i < 20; i++) { | 193 for (var i = 0; i < 20; i++) { |
195 TryCatchTest.testMain(); | 194 TryCatchTest.testMain(); |
196 } | 195 } |
197 } | 196 } |
OLD | NEW |