OLD | NEW |
| (Empty) |
1 // Copyright (c) 2013, 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 import "package:expect/expect.dart"; | |
6 | |
7 void argument() { | |
8 throw new ArgumentError(499); | |
9 } | |
10 | |
11 void noSuchMethod() { | |
12 (499).doesNotExist(); | |
13 } | |
14 | |
15 void nullThrown() { | |
16 throw null; | |
17 } | |
18 | |
19 void range() { | |
20 throw new RangeError.range(0, 1, 2); | |
21 } | |
22 | |
23 void fallThrough() { | |
24 nested() {} | |
25 | |
26 switch (5) { | |
27 case 5: | |
28 nested(); | |
29 default: | |
30 Expect.fail("Should not reach"); | |
31 } | |
32 } | |
33 | |
34 abstract class A { | |
35 foo(); | |
36 } | |
37 | |
38 void abstractClassInstantiation() { | |
39 new A(); | |
40 } | |
41 | |
42 void unsupported() { | |
43 throw new UnsupportedError("unsupported"); | |
44 } | |
45 | |
46 void unimplemented() { | |
47 throw new UnimplementedError("unimplemented"); | |
48 } | |
49 | |
50 void state() { | |
51 return [1, 2].single; | |
52 } | |
53 | |
54 void type() { | |
55 return 1 + "string"; | |
56 } | |
57 | |
58 main() { | |
59 List<Function> errorFunctions = [ | |
60 argument, | |
61 noSuchMethod, | |
62 nullThrown, | |
63 range, | |
64 fallThrough, | |
65 abstractClassInstantiation, | |
66 unsupported, | |
67 unimplemented, | |
68 state, | |
69 type | |
70 ]; | |
71 | |
72 for (var f in errorFunctions) { | |
73 bool hasThrown = false; | |
74 try { | |
75 f(); | |
76 } catch (e) { | |
77 hasThrown = true; | |
78 Expect.isTrue( | |
79 e.stackTrace is StackTrace, "$e doesn't have a non-null stack trace"); | |
80 } | |
81 Expect.isTrue(hasThrown); | |
82 } | |
83 } | |
OLD | NEW |