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 // Dart test program for testing throw statement | |
| 5 | |
| 6 import "package:expect/expect.dart"; | |
| 7 | |
| 8 class MyException { | |
| 9 const MyException(String message) : message_ = message; | |
| 10 final String message_; | |
| 11 } | |
| 12 | |
| 13 class Helper1 { | |
| 14 static int func1() { | |
| 15 return func2(); | |
| 16 } | |
| 17 static int func2() { | |
| 18 return func3(); | |
| 19 } | |
| 20 static int func3() { | |
| 21 return func4(); | |
| 22 } | |
| 23 static int func4() { | |
| 24 var i = 0; | |
| 25 try { | |
| 26 i = 10; | |
| 27 func5(); | |
| 28 } on ArgumentError catch (e) { | |
| 29 i = 100; | |
| 30 Expect.isNotNull(e.stackTrace, "Errors need a stackTrace on throw"); | |
| 31 } | |
| 32 return i; | |
| 33 } | |
| 34 static void func5() { | |
| 35 // Throw an Error. | |
| 36 throw new ArgumentError("ArgumentError in func5"); | |
| 37 } | |
| 38 } | |
| 39 | |
| 40 class Helper2 { | |
| 41 static int func1() { | |
| 42 return func2(); | |
| 43 } | |
| 44 static int func2() { | |
| 45 return func3(); | |
| 46 } | |
| 47 static int func3() { | |
| 48 return func4(); | |
| 49 } | |
| 50 static int func4() { | |
| 51 var i = 0; | |
| 52 try { | |
| 53 i = 10; | |
| 54 func5(); | |
| 55 } on OutOfMemoryError catch (e) { | |
|
ahe
2013/07/25 09:01:26
I'm not sure we can support this in dart2js. It i
siva
2013/07/25 17:40:25
I have moved this into standalone/oom_error_stackt
| |
| 56 i = 200; | |
| 57 Expect.isNull(e.stackTrace, "OOM should not have a stackTrace on throw"); | |
| 58 } | |
| 59 return i; | |
| 60 } | |
| 61 static List func5() { | |
| 62 // Cause an OOM(out of memory) exception. | |
| 63 var l1 = new List(268435455); | |
| 64 return l1; | |
| 65 } | |
| 66 } | |
| 67 | |
| 68 class Helper3 { | |
| 69 static int func1() { | |
| 70 return func2(); | |
| 71 } | |
| 72 static int func2() { | |
| 73 return func3(); | |
| 74 } | |
| 75 static int func3() { | |
| 76 return func4(); | |
| 77 } | |
| 78 static int func4() { | |
| 79 var i = 0; | |
| 80 try { | |
| 81 i = 10; | |
| 82 func5(); | |
| 83 } on ArgumentError catch (e, s) { | |
| 84 i = 300; | |
| 85 Expect.isNotNull(e.stackTrace, "Errors need a stackTrace on throw"); | |
| 86 Expect.isFalse(identical(e.stackTrace, s)); | |
| 87 Expect.equals(e.stackTrace.toString(), s.toString()); | |
| 88 } | |
| 89 return i; | |
| 90 } | |
| 91 static List func5() { | |
| 92 // Throw an Error. | |
| 93 throw new ArgumentError("ArgumentError in func5"); | |
| 94 } | |
| 95 } | |
| 96 | |
| 97 class Helper4 { | |
| 98 static int func1() { | |
| 99 return func2(); | |
| 100 } | |
| 101 static int func2() { | |
| 102 return func3(); | |
| 103 } | |
| 104 static int func3() { | |
| 105 return func4(); | |
| 106 } | |
| 107 static int func4() { | |
| 108 var i = 0; | |
| 109 try { | |
| 110 i = 10; | |
| 111 func5(); | |
| 112 } on MyException catch (e) { | |
| 113 i = 400; | |
| 114 try { | |
| 115 Expect.isNull(e.stackTrace, "Do not expect a stackTrace on throw here"); | |
| 116 } on NoSuchMethodError catch (e) { | |
|
ahe
2013/07/25 09:01:26
This seems a bit convoluted. You expect e.stackTra
siva
2013/07/25 17:40:25
Changed line to just access stackTrace without the
| |
| 117 Expect.isNotNull(e.stackTrace, "Error needs a stackTrace on throw"); | |
| 118 } | |
| 119 } | |
| 120 return i; | |
| 121 } | |
| 122 static List func5() { | |
| 123 // Throw an Exception (any random object). | |
| 124 throw new MyException("MyException in func5"); | |
| 125 } | |
| 126 } | |
| 127 | |
| 128 class ErrorStackTraceTest { | |
| 129 static testMain() { | |
| 130 Expect.equals(100, Helper1.func1()); | |
| 131 Expect.equals(200, Helper2.func1()); | |
| 132 Expect.equals(300, Helper3.func1()); | |
| 133 Expect.equals(400, Helper4.func1()); | |
| 134 } | |
| 135 } | |
| 136 | |
| 137 main() { | |
| 138 ErrorStackTraceTest.testMain(); | |
| 139 } | |
| OLD | NEW |