| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2014, 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 class NotASubclassOfError {} |
| 6 |
| 7 fail() => throw "Fail"; |
| 8 |
| 9 // == Rethrow, skipping through typed handlers. == |
| 10 |
| 11 aa1() { |
| 12 try { |
| 13 bb1(); |
| 14 fail(); |
| 15 } catch(exception, stacktrace) { |
| 16 expectTrace(['gg1', 'ff1', 'ee1', 'dd1', 'cc1', 'bb1', 'aa1'], |
| 17 stacktrace); |
| 18 } |
| 19 } |
| 20 |
| 21 bb1() => cc1(); |
| 22 |
| 23 cc1() { |
| 24 try { |
| 25 dd1(); |
| 26 } on String catch(e) { |
| 27 fail(); |
| 28 } on int catch(e) { |
| 29 fail(); |
| 30 } |
| 31 } |
| 32 |
| 33 dd1() => ee1(); |
| 34 |
| 35 ee1() { |
| 36 try { |
| 37 ff1(); |
| 38 } catch(e) { |
| 39 rethrow; |
| 40 } |
| 41 } |
| 42 |
| 43 ff1() => gg1(); |
| 44 |
| 45 gg1() => throw new NotASubclassOfError(); |
| 46 |
| 47 // == Rethrow, rethrow again in typed handler. == |
| 48 |
| 49 aa2() { |
| 50 try { |
| 51 bb2(); |
| 52 fail(); |
| 53 } catch(exception, stacktrace) { |
| 54 expectTrace(['gg2', 'ff2', 'ee2', 'dd2', 'cc2', 'bb2', 'aa2'], |
| 55 stacktrace); |
| 56 } |
| 57 } |
| 58 |
| 59 bb2() => cc2(); |
| 60 |
| 61 cc2() { |
| 62 try { |
| 63 dd2(); |
| 64 } on NotASubclassOfError catch(e) { |
| 65 rethrow; |
| 66 } on int catch(e) { |
| 67 fail(); |
| 68 } |
| 69 } |
| 70 |
| 71 dd2() => ee2(); |
| 72 |
| 73 ee2() { |
| 74 try { |
| 75 ff2(); |
| 76 } catch(e) { |
| 77 rethrow; |
| 78 } |
| 79 } |
| 80 |
| 81 ff2() => gg2(); |
| 82 |
| 83 gg2() => throw new NotASubclassOfError(); |
| 84 |
| 85 // == Rethrow, with intervening catch without a trace parameter. |
| 86 |
| 87 aa3() { |
| 88 try { |
| 89 bb3(); |
| 90 fail(); |
| 91 } catch(exception, stacktrace) { |
| 92 expectTrace(['cc3', 'bb3', 'aa3'], stacktrace); |
| 93 } |
| 94 } |
| 95 |
| 96 bb3() => cc3(); |
| 97 |
| 98 cc3() { |
| 99 try { |
| 100 dd3(); |
| 101 } catch(e) { |
| 102 throw e; |
| 103 } |
| 104 } |
| 105 |
| 106 dd3() => ee3(); |
| 107 |
| 108 ee3() { |
| 109 try { |
| 110 ff3(); |
| 111 } catch(e) { |
| 112 rethrow; |
| 113 } |
| 114 } |
| 115 |
| 116 ff3() => gg3(); |
| 117 |
| 118 gg3() => throw new NotASubclassOfError(); |
| 119 |
| 120 expectTrace(functionNames, stacktrace) { |
| 121 // Note we don't expect functionNames to cover the whole trace, only the |
| 122 // top portion, because the frames below main are an implementation detail. |
| 123 var traceLines = stacktrace.toString().split('\n'); |
| 124 var expectedIndex = 0; |
| 125 var actualIndex = 0; |
| 126 print(stacktrace); |
| 127 print(functionNames); |
| 128 while (expectedIndex < functionNames.length) { |
| 129 var expected = functionNames[expectedIndex]; |
| 130 var actual = traceLines[actualIndex]; |
| 131 if (actual.indexOf(expected) == -1) { |
| 132 if (expectedIndex == 0) { |
| 133 actualIndex++; // Skip over some helper frames at the top |
| 134 } else { |
| 135 throw "Expected: $expected actual: $actual"; |
| 136 } |
| 137 } else { |
| 138 actualIndex++; |
| 139 expectedIndex++; |
| 140 } |
| 141 } |
| 142 } |
| 143 |
| 144 main() { |
| 145 aa1(); |
| 146 aa2(); |
| 147 aa3(); |
| 148 } |
| OLD | NEW |