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 | 4 |
5 import "package:expect/expect.dart"; | 5 import "package:expect/expect.dart"; |
6 | 6 |
7 class MyException { } | 7 class MyException {} |
8 | 8 |
9 class MyException1 extends MyException { } | 9 class MyException1 extends MyException {} |
10 | 10 |
11 class MyException2 extends MyException { } | 11 class MyException2 extends MyException {} |
12 | 12 |
13 void test1() { | 13 void test1() { |
14 var foo = 0; | 14 var foo = 0; |
15 try { | 15 try { |
16 throw new MyException1(); | 16 throw new MyException1(); |
17 } | 17 } |
18 on on MyException2 catch (e) { } //# 02: compile-time error | 18 on on MyException2 catch (e) { } //# 02: compile-time error |
19 catch MyException2 catch (e) { } //# 03: compile-time error | 19 catch MyException2 catch (e) { } //# 03: compile-time error |
20 catch catch catch (e) { } //# 04: compile-time error | 20 catch catch catch (e) { } //# 04: compile-time error |
21 on (e) { } //# 05: compile-time error | 21 on (e) { } //# 05: compile-time error |
22 catch MyException2 catch (e) { } //# 06: compile-time error | 22 catch MyException2 catch (e) { } //# 06: compile-time error |
23 on MyException2 catch (e) { | 23 on MyException2 catch (e) { |
24 foo = 1; | 24 foo = 1; |
25 } on MyException1 catch (e) { | 25 } on MyException1 catch (e) { |
26 foo = 2; | 26 foo = 2; |
27 } on MyException catch (e) { | 27 } on MyException catch (e) { |
28 foo = 3; | 28 foo = 3; |
29 } | 29 } |
30 on UndefinedClass //# 07: static type warning | 30 on UndefinedClass //# 07: static type warning |
31 catch(e) { foo = 4; } | 31 catch (e) { |
| 32 foo = 4; |
| 33 } |
32 Expect.equals(2, foo); | 34 Expect.equals(2, foo); |
33 } | 35 } |
34 | 36 |
35 testFinal() { | 37 testFinal() { |
36 try { | 38 try { |
37 throw "catch this!"; | 39 throw "catch this!"; |
38 } catch (e, s) { | 40 } catch (e, s) { |
39 // Test that the error and stack trace variables are final. | 41 // Test that the error and stack trace variables are final. |
40 e = null; // //# 10: runtime error | 42 e = null; // //# 10: runtime error |
41 s = null; // //# 11: runtime error | 43 s = null; // //# 11: runtime error |
42 } | 44 } |
43 } | 45 } |
44 | 46 |
45 main() { | 47 main() { |
46 test1(); | 48 test1(); |
47 testFinal(); | 49 testFinal(); |
48 } | 50 } |
OLD | NEW |