| 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 // Dart test program for testing throw statement | 4 // Dart test program for testing throw statement |
| 5 | 5 |
| 6 import "package:expect/expect.dart"; | 6 import "package:expect/expect.dart"; |
| 7 | 7 |
| 8 class MyException { | 8 class MyException { |
| 9 const MyException(); | 9 const MyException(); |
| 10 } | 10 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 } | 22 } |
| 23 | 23 |
| 24 void testRethrowPastUncaught() { | 24 void testRethrowPastUncaught() { |
| 25 try { | 25 try { |
| 26 try { | 26 try { |
| 27 try { | 27 try { |
| 28 throwException(); | 28 throwException(); |
| 29 Expect.fail("Should have thrown an exception"); | 29 Expect.fail("Should have thrown an exception"); |
| 30 } catch (e) { | 30 } catch (e) { |
| 31 Expect.equals(true, identical(e, currentException)); | 31 Expect.equals(true, identical(e, currentException)); |
| 32 throw; | 32 rethrow; |
| 33 Expect.fail("Should have thrown an exception"); | 33 Expect.fail("Should have thrown an exception"); |
| 34 } | 34 } |
| 35 } on OtherException catch (e) { | 35 } on OtherException catch (e) { |
| 36 Expect.fail("Should not have caught OtherException"); | 36 Expect.fail("Should not have caught OtherException"); |
| 37 } | 37 } |
| 38 } catch (e) { | 38 } catch (e) { |
| 39 Expect.equals(true, identical(e, currentException)); | 39 Expect.equals(true, identical(e, currentException)); |
| 40 } | 40 } |
| 41 } | 41 } |
| 42 | 42 |
| 43 void testRethrow() { | 43 void testRethrow() { |
| 44 try { | 44 try { |
| 45 try { | 45 try { |
| 46 throwException(); | 46 throwException(); |
| 47 Expect.fail("Should have thrown an exception"); | 47 Expect.fail("Should have thrown an exception"); |
| 48 } catch (e) { | 48 } catch (e) { |
| 49 Expect.equals(true, identical(e, currentException)); | 49 Expect.equals(true, identical(e, currentException)); |
| 50 throw; | 50 rethrow; |
| 51 Expect.fail("Should have thrown an exception"); | 51 Expect.fail("Should have thrown an exception"); |
| 52 } | 52 } |
| 53 } catch (e) { | 53 } catch (e) { |
| 54 Expect.equals(true, identical(e, currentException)); | 54 Expect.equals(true, identical(e, currentException)); |
| 55 } | 55 } |
| 56 } | 56 } |
| 57 } | 57 } |
| 58 | 58 |
| 59 main() { | 59 main() { |
| 60 RethrowTest t = new RethrowTest(); | 60 RethrowTest t = new RethrowTest(); |
| 61 t.testRethrow(); | 61 t.testRethrow(); |
| 62 t.testRethrowPastUncaught(); | 62 t.testRethrowPastUncaught(); |
| 63 } | 63 } |
| OLD | NEW |