| 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 class MyException { | 5 class MyException { } |
| 6 MyException() {} | |
| 7 } | |
| 8 | 6 |
| 9 class MyException1 extends MyException { | 7 class MyException1 extends MyException { } |
| 10 MyException1() : super() {} | |
| 11 } | |
| 12 | 8 |
| 13 class MyException2 extends MyException { | 9 class MyException2 extends MyException { } |
| 14 MyException2() : super() {} | |
| 15 } | |
| 16 | 10 |
| 17 class TryCatchTest { | 11 class TryCatchTest { |
| 18 static void test1() { | 12 static void test1() { |
| 19 var foo = 0; | 13 var foo = 0; |
| 20 try { | 14 try { |
| 21 throw new MyException1(); | 15 throw new MyException1(); |
| 22 } catch (MyException2 e) { | 16 } on MyException2 catch (e) { |
| 23 foo = 1; | 17 foo = 1; |
| 24 } catch (MyException1 e) { | 18 } on MyException1 catch (e) { |
| 25 foo = 2; | 19 foo = 2; |
| 26 } catch (MyException e) { | 20 } on MyException catch (e) { |
| 27 foo = 3; | 21 foo = 3; |
| 28 } | 22 } |
| 29 Expect.equals(2, foo); | 23 Expect.equals(2, foo); |
| 30 } | 24 } |
| 31 | 25 |
| 32 static void test2() { | 26 static void test2() { |
| 33 var foo = 0; | 27 var foo = 0; |
| 34 try { | 28 try { |
| 35 throw new MyException1(); | 29 throw new MyException1(); |
| 36 } catch (MyException2 e) { | 30 } on MyException2 catch (e) { |
| 37 foo = 1; | 31 foo = 1; |
| 38 } catch (MyException e) { | 32 } on MyException catch (e) { |
| 39 foo = 2; | 33 foo = 2; |
| 40 } catch (MyException1 e) { | 34 } on MyException1 catch (e) { |
| 41 foo = 3; | 35 foo = 3; |
| 42 } | 36 } |
| 43 Expect.equals(2, foo); | 37 Expect.equals(2, foo); |
| 44 } | 38 } |
| 45 | 39 |
| 46 static void test3() { | 40 static void test3() { |
| 47 var foo = 0; | 41 var foo = 0; |
| 48 try { | 42 try { |
| 49 throw new MyException(); | 43 throw new MyException(); |
| 50 } catch (MyException2 e) { | 44 } on MyException2 catch (e) { |
| 51 foo = 1; | 45 foo = 1; |
| 52 } catch (MyException1 e) { | 46 } on MyException1 catch (e) { |
| 53 foo = 2; | 47 foo = 2; |
| 54 } catch (MyException e) { | 48 } on MyException catch (e) { |
| 55 foo = 3; | 49 foo = 3; |
| 56 } | 50 } |
| 57 Expect.equals(3, foo); | 51 Expect.equals(3, foo); |
| 58 } | 52 } |
| 59 | 53 |
| 60 static void test4() { | 54 static void test4() { |
| 61 var foo = 0; | 55 var foo = 0; |
| 62 try { | 56 try { |
| 63 try { | 57 try { |
| 64 throw new MyException(); | 58 throw new MyException(); |
| 65 } catch (MyException2 e) { | 59 } on MyException2 catch (e) { |
| 66 foo = 1; | 60 foo = 1; |
| 67 } catch (MyException1 e) { | 61 } on MyException1 catch (e) { |
| 68 foo = 2; | 62 foo = 2; |
| 69 } | 63 } |
| 70 } catch (MyException e) { | 64 } on MyException catch (e) { |
| 71 Expect.equals(0, foo); | 65 Expect.equals(0, foo); |
| 72 foo = 3; | 66 foo = 3; |
| 73 } | 67 } |
| 74 Expect.equals(3, foo); | 68 Expect.equals(3, foo); |
| 75 } | 69 } |
| 76 | 70 |
| 77 static void test5() { | 71 static void test5() { |
| 78 var foo = 0; | 72 var foo = 0; |
| 79 try { | 73 try { |
| 80 throw new MyException1(); | 74 throw new MyException1(); |
| 81 } catch (MyException2 e) { | 75 } on MyException2 catch (e) { |
| 82 foo = 1; | 76 foo = 1; |
| 83 } catch (var e) { | 77 } catch (e) { |
| 84 foo = 2; | 78 foo = 2; |
| 85 } | 79 } |
| 86 Expect.equals(2, foo); | 80 Expect.equals(2, foo); |
| 87 } | 81 } |
| 88 | 82 |
| 89 static void test6() { | 83 static void test6() { |
| 90 var foo = 0; | 84 var foo = 0; |
| 91 try { | 85 try { |
| 92 throw new MyException(); | 86 throw new MyException(); |
| 93 } catch (MyException2 e) { | 87 } on MyException2 catch (e) { |
| 94 foo = 1; | 88 foo = 1; |
| 95 } catch (MyException1 e) { | 89 } on MyException1 catch (e) { |
| 96 foo = 2; | 90 foo = 2; |
| 97 } catch (var e) { | 91 } catch (e) { |
| 98 foo = 3; | 92 foo = 3; |
| 99 } | 93 } |
| 100 Expect.equals(3, foo); | 94 Expect.equals(3, foo); |
| 101 } | 95 } |
| 102 | 96 |
| 103 static void test7() { | 97 static void test7() { |
| 104 var foo = 0; | 98 var foo = 0; |
| 105 try { | 99 try { |
| 106 try { | 100 try { |
| 107 throw new MyException(); | 101 throw new MyException(); |
| 108 } catch (MyException2 e) { | 102 } on MyException2 catch (e) { |
| 109 foo = 1; | 103 foo = 1; |
| 110 } catch (MyException1 e) { | 104 } on MyException1 catch (e) { |
| 111 foo = 2; | 105 foo = 2; |
| 112 } | 106 } |
| 113 } catch (var e) { | 107 } catch (e) { |
| 114 Expect.equals(0, foo); | 108 Expect.equals(0, foo); |
| 115 foo = 3; | 109 foo = 3; |
| 116 } | 110 } |
| 117 Expect.equals(3, foo); | 111 Expect.equals(3, foo); |
| 118 } | 112 } |
| 119 | 113 |
| 120 static void test8() { | 114 static void test8() { |
| 121 var e = 3; | 115 var e = 3; |
| 122 var caught = false; | 116 var caught = false; |
| 123 try { | 117 try { |
| 124 throw new MyException(); | 118 throw new MyException(); |
| 125 } catch (var exc) { | 119 } catch (exc) { |
| 126 caught = true; | 120 caught = true; |
| 127 } | 121 } |
| 128 Expect.equals(true, caught); | 122 Expect.equals(true, caught); |
| 129 Expect.equals(3, e); | 123 Expect.equals(3, e); |
| 130 } | 124 } |
| 131 | 125 |
| 132 static void testMain() { | 126 static void testMain() { |
| 133 test1(); | 127 test1(); |
| 134 test2(); | 128 test2(); |
| 135 test3(); | 129 test3(); |
| 136 test4(); | 130 test4(); |
| 137 test5(); | 131 test5(); |
| 138 test6(); | 132 test6(); |
| 139 test7(); | 133 test7(); |
| 140 test8(); | 134 test8(); |
| 141 } | 135 } |
| 142 } | 136 } |
| 143 | 137 |
| 144 main() { | 138 main() { |
| 145 TryCatchTest.testMain(); | 139 TryCatchTest.testMain(); |
| 146 } | 140 } |
| OLD | NEW |