OLD | NEW |
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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 main() { | 5 main() { |
6 try { | 6 try { |
7 print('hello1'); | 7 print('hello1'); |
8 } catch (e, _) {} finally { | 8 } catch (e, _) {} finally { |
9 print('hello2'); | 9 print('hello2'); |
10 } | 10 } |
11 print('hello3'); | 11 print('hello3'); |
12 print(foo()); | 12 print(fReturns()); |
13 print(bar()); | 13 print(fFinalizes()); |
| 14 print(fThrows()); |
14 } | 15 } |
15 | 16 |
16 int foo() { | 17 /// Tests that the return in finally is executed. |
| 18 int fReturns() { |
17 try { | 19 try { |
18 print('foo 1'); | 20 print('foo 1'); |
19 return 1; | 21 return 1; |
20 } catch (e, _) {} finally { | 22 } catch (e, _) {} finally { |
21 print('foo 2'); | 23 print('foo 2'); |
22 return 2; | 24 return 2; |
23 } | 25 } |
24 } | 26 } |
25 | 27 |
26 int bar() { | 28 /// Tests that finally is executed before returning. |
| 29 int fFinalizes() { |
27 try { | 30 try { |
28 print('bar 1'); | 31 print('bar 1'); |
29 return 1; | 32 return 1; |
30 } catch (e, _) {} finally { | 33 } catch (e, _) {} finally { |
31 print('bar 2'); | 34 print('bar 2'); |
32 } | 35 } |
33 return 0; | 36 return 0; |
34 } | 37 } |
| 38 |
| 39 /// Tests that the exception is caught. |
| 40 int fThrows() { |
| 41 try { |
| 42 print(37); |
| 43 throw 'Error'; |
| 44 } catch (e, _) { |
| 45 print('Caught $e'); |
| 46 } finally { |
| 47 print("Finalizer"); |
| 48 } |
| 49 return 34; |
| 50 } |
OLD | NEW |