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 { } |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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() { |
| 151 var e0 = 11; |
| 152 try { |
| 153 throw "up"; |
| 154 } on int catch (e0) { |
| 155 Expect.fail("unreachable"); |
| 156 } on String catch (e1) { |
| 157 // e0 from the other catch clause is not in scope. |
| 158 Expect.equals(11, e0); |
| 159 } |
| 160 } |
| 161 |
| 162 static void test12() { |
| 163 const x = const []; |
| 164 try { |
| 165 throw "up"; |
| 166 } catch (e) { |
| 167 Expect.equals("up", e); |
| 168 } on String catch (e) { |
| 169 // Compile-time constants in unreachable catch blocks are still |
| 170 // compiled. |
| 171 const y = x[0]; /// 01: compile-time error |
| 172 Expect.fail("unreachable"); |
| 173 } |
| 174 } |
| 175 |
| 176 |
150 static void testMain() { | 177 static void testMain() { |
151 test1(); | 178 test1(); |
152 test2(); | 179 test2(); |
153 test3(); | 180 test3(); |
154 test4(); | 181 test4(); |
155 test5(); | 182 test5(); |
156 test6(); | 183 test6(); |
157 test7(); | 184 test7(); |
158 test8(); | 185 test8(); |
159 test9(); | 186 test9(); |
160 test10(); | 187 test10(); |
| 188 test11(); |
| 189 test12(); |
161 } | 190 } |
162 } | 191 } |
163 | 192 |
164 main() { | 193 main() { |
165 for (var i = 0; i < 20; i++) { | 194 for (var i = 0; i < 20; i++) { |
166 TryCatchTest.testMain(); | 195 TryCatchTest.testMain(); |
167 } | 196 } |
168 } | 197 } |
OLD | NEW |