OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
| 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. |
| 4 |
| 5 // Test correct handling of try-catch inside try-finally. |
| 6 |
| 7 import "package:expect/expect.dart"; |
| 8 |
| 9 void main() { |
| 10 print("== test1 =="); |
| 11 bool caught = false; |
| 12 try { |
| 13 test1(); |
| 14 print("Unexpected 1"); // should never go here |
| 15 Expect.isTrue(false); |
| 16 } catch (e) { |
| 17 caught = true; |
| 18 print("main catch 1: $e"); |
| 19 Expect.equals(e, "Ball"); |
| 20 } |
| 21 Expect.isTrue(caught); |
| 22 print("== test2 =="); |
| 23 caught = false; |
| 24 try { |
| 25 test2(); |
| 26 print("Unexpected 2"); // should never go here |
| 27 Expect.isTrue(false); |
| 28 } catch (e) { |
| 29 caught = true; |
| 30 print("main catch 2: $e"); |
| 31 Expect.equals(e, "Ball"); |
| 32 } |
| 33 Expect.isTrue(caught); |
| 34 } |
| 35 |
| 36 void test1() { |
| 37 try { |
| 38 throw "Ball"; |
| 39 } finally { |
| 40 try { |
| 41 throw "Frisbee"; |
| 42 } catch(e) { |
| 43 print("test 1 catch: $e"); |
| 44 Expect.equals(e, "Frisbee"); |
| 45 } |
| 46 } |
| 47 } |
| 48 |
| 49 void test2() { |
| 50 try { |
| 51 throwError(); // call a method that throws an error |
| 52 } finally { |
| 53 try { |
| 54 throw "Frisbee"; |
| 55 } catch(e) { |
| 56 print("test 2 catch: $e"); |
| 57 Expect.equals(e, "Frisbee"); |
| 58 } |
| 59 } |
| 60 } |
| 61 |
| 62 |
| 63 void throwError() { |
| 64 throw "Ball"; |
| 65 } |
OLD | NEW |