OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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"; | |
6 | |
7 int x = "milou"; | 5 int x = "milou"; |
8 bool inCheckedMode = false; | 6 bool inCheckedMode = false; |
9 | 7 |
10 bool readXThrows() { | 8 bool readXThrows() { |
11 try { | 9 try { |
12 var y = x; | 10 var y = x; |
13 return false; | 11 return false; |
14 } catch (e) { | 12 } catch (e) { |
15 inCheckedMode = true; | 13 inCheckedMode = true; |
16 x = 5; // Make sure we do not throw exception a second time. | 14 x = 5; // Make sure we do not throw exception a second time. |
17 return true; | 15 return true; |
18 } | 16 } |
19 } | 17 } |
20 | 18 |
21 main() { | 19 main() { |
22 int numExceptions = 0; | 20 int numExceptions = 0; |
23 for (int i = 0; i < 8; i++) { | 21 for (int i = 0; i < 8; i++) { |
24 if (readXThrows()) { | 22 if (readXThrows()) { |
25 numExceptions++; | 23 numExceptions++; |
26 } | 24 } |
27 } | 25 } |
28 // In checked mode throw only one exception. | 26 // In checked mode throw only one exception. |
29 Expect.equals(inCheckedMode ? 1 : 0, numExceptions); | 27 Expect.equals(inCheckedMode ? 1 : 0, numExceptions); |
30 } | 28 } |
OLD | NEW |