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 class TryCatchTest { | 13 class TryCatchTest { |
14 static void test1() { | 14 static void test1() { |
15 var foo = 0; | 15 var foo = 0; |
16 try { | 16 try { |
17 throw new MyException1(); | 17 throw new MyException1(); |
18 } | 18 } |
19 on MyException3 catch (e) { } /// 01: compile-time error | |
20 on on MyException2 catch (e) { } /// 02: compile-time error | 19 on on MyException2 catch (e) { } /// 02: compile-time error |
21 catch MyException2 catch (e) { } /// 03: compile-time error | 20 catch MyException2 catch (e) { } /// 03: compile-time error |
22 catch catch catch (e) { } /// 04: compile-time error | 21 catch catch catch (e) { } /// 04: compile-time error |
23 on (e) { } /// 05: compile-time error | 22 on (e) { } /// 05: compile-time error |
24 catch MyException2 catch (e) { } /// 06: compile-time error | 23 catch MyException2 catch (e) { } /// 06: compile-time error |
25 on MyException2 catch (e) { | 24 on MyException2 catch (e) { |
26 foo = 1; | 25 foo = 1; |
27 } on MyException1 catch (e) { | 26 } on MyException1 catch (e) { |
28 foo = 2; | 27 foo = 2; |
29 } on MyException catch (e) { | 28 } on MyException catch (e) { |
30 foo = 3; | 29 foo = 3; |
31 } | 30 } |
32 on UndefinedClass /// 07: compile-time error | 31 on UndefinedClass /// 07: static type warning |
33 catch(e) { foo = 4; } | 32 catch(e) { foo = 4; } |
34 Expect.equals(2, foo); | 33 Expect.equals(2, foo); |
35 } | 34 } |
36 | 35 |
37 static void testMain() { | 36 static void testMain() { |
38 test1(); | 37 test1(); |
39 } | 38 } |
40 } | 39 } |
41 | 40 |
42 main() { | 41 main() { |
43 TryCatchTest.testMain(); | 42 TryCatchTest.testMain(); |
44 } | 43 } |
OLD | NEW |