Chromium Code Reviews| 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 argument() { | |
|
Lasse Reichstein Nielsen
2013/07/03 13:06:13
void return type, please. Makes it more readable.
floitsch
2013/07/03 14:50:20
Done.
| |
| 8 throw new ArgumentError(499); | |
| 9 } | |
| 10 | |
| 11 noSuchMethod() { | |
| 12 (499).doesNotExist(); | |
| 13 } | |
| 14 | |
| 15 nullThrown() { | |
| 16 throw null; | |
| 17 } | |
| 18 | |
| 19 range() { | |
| 20 throw new RangeError.range(0, 1, 2); | |
| 21 } | |
| 22 | |
| 23 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 abstractClassInstantiation() { | |
| 39 new A(); | |
| 40 } | |
| 41 | |
| 42 unsupported() { | |
| 43 throw new UnsupportedError("unsupported"); | |
| 44 } | |
| 45 | |
| 46 unimplemented() { | |
| 47 throw new UnimplementedError("unimplemented"); | |
| 48 } | |
| 49 | |
| 50 state() { | |
| 51 return [1, 2].single; | |
| 52 } | |
| 53 | |
| 54 type() { | |
| 55 return 1 + "string"; | |
| 56 } | |
| 57 | |
| 58 main() { | |
| 59 List<Function> errorFunctions = [ | |
| 60 argument, noSuchMethod, nullThrown, range, fallThrough, | |
| 61 abstractClassInstantiation, unsupported, unimplemented, state, | |
| 62 type ]; | |
| 63 | |
| 64 for (var f in errorFunctions) { | |
| 65 bool hasThrown = false; | |
| 66 try { | |
| 67 f(); | |
| 68 } catch(e) { | |
| 69 hasThrown = true; | |
| 70 Expect.isTrue(e.stackTrace is StackTrace, | |
| 71 "$e doesn't have a non-null stack trace"); | |
| 72 } | |
| 73 Expect.isTrue(hasThrown); | |
| 74 } | |
| 75 } | |
| OLD | NEW |