OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 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 | 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 // Dart test program for testing throw statement | 4 // Dart test program for testing throw statement |
5 | 5 |
6 import "package:expect/expect.dart"; | 6 import "package:expect/expect.dart"; |
7 | 7 |
8 class MyException { | 8 class MyException { |
9 const MyException(String message) : message_ = message; | 9 const MyException(String message) : message_ = message; |
10 final String message_; | 10 final String message_; |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 static int func4() { | 78 static int func4() { |
79 var i = 0; | 79 var i = 0; |
80 try { | 80 try { |
81 i = 10; | 81 i = 10; |
82 func5(); | 82 func5(); |
83 } on MyException catch (e) { | 83 } on MyException catch (e) { |
84 i = 300; | 84 i = 300; |
85 try { | 85 try { |
86 // There should be no stackTrace in this normal exception object. | 86 // There should be no stackTrace in this normal exception object. |
87 // We should get a NoSuchMethodError. | 87 // We should get a NoSuchMethodError. |
88 var trace = e.stackTrace; /// static type warning | 88 var trace = e.stackTrace; //# static type warning |
89 } on NoSuchMethodError catch (e) { | 89 } on NoSuchMethodError catch (e) { |
90 Expect.isNotNull(e.stackTrace, "Error needs a stackTrace on throw"); | 90 Expect.isNotNull(e.stackTrace, "Error needs a stackTrace on throw"); |
91 } | 91 } |
92 } | 92 } |
93 return i; | 93 return i; |
94 } | 94 } |
95 static List func5() { | 95 static List func5() { |
96 // Throw an Exception (any random object). | 96 // Throw an Exception (any random object). |
97 throw new MyException("MyException in func5"); | 97 throw new MyException("MyException in func5"); |
98 } | 98 } |
99 } | 99 } |
100 | 100 |
101 class ErrorStackTraceTest { | 101 class ErrorStackTraceTest { |
102 static testMain() { | 102 static testMain() { |
103 Expect.equals(100, Helper1.func1()); | 103 Expect.equals(100, Helper1.func1()); |
104 Expect.equals(200, Helper2.func1()); | 104 Expect.equals(200, Helper2.func1()); |
105 Expect.equals(300, Helper3.func1()); | 105 Expect.equals(300, Helper3.func1()); |
106 } | 106 } |
107 } | 107 } |
108 | 108 |
109 main() { | 109 main() { |
110 ErrorStackTraceTest.testMain(); | 110 ErrorStackTraceTest.testMain(); |
111 } | 111 } |
OLD | NEW |