| 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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 return func4(); | 77 return func4(); |
| 78 } | 78 } |
| 79 static int func4() { | 79 static int func4() { |
| 80 var i = 0; | 80 var i = 0; |
| 81 try { | 81 try { |
| 82 i = 10; | 82 i = 10; |
| 83 func5(); | 83 func5(); |
| 84 } on MyException catch (e) { | 84 } on MyException catch (e) { |
| 85 i = 300; | 85 i = 300; |
| 86 try { | 86 try { |
| 87 // There should be no stackTrace in this normal excpetion object. | 87 // There should be no stackTrace in this normal exception object. |
| 88 // We should get a NoSuchMethodError. | 88 // We should get a NoSuchMethodError. |
| 89 var trace = e.stackTrace; | 89 var trace = e.stackTrace; /// static type warning |
| 90 } on NoSuchMethodError catch (e) { | 90 } on NoSuchMethodError catch (e) { |
| 91 Expect.isNotNull(e.stackTrace, "Error needs a stackTrace on throw"); | 91 Expect.isNotNull(e.stackTrace, "Error needs a stackTrace on throw"); |
| 92 } | 92 } |
| 93 } | 93 } |
| 94 return i; | 94 return i; |
| 95 } | 95 } |
| 96 static List func5() { | 96 static List func5() { |
| 97 // Throw an Exception (any random object). | 97 // Throw an Exception (any random object). |
| 98 throw new MyException("MyException in func5"); | 98 throw new MyException("MyException in func5"); |
| 99 } | 99 } |
| 100 } | 100 } |
| 101 | 101 |
| 102 class ErrorStackTraceTest { | 102 class ErrorStackTraceTest { |
| 103 static testMain() { | 103 static testMain() { |
| 104 Expect.equals(100, Helper1.func1()); | 104 Expect.equals(100, Helper1.func1()); |
| 105 Expect.equals(200, Helper2.func1()); | 105 Expect.equals(200, Helper2.func1()); |
| 106 Expect.equals(300, Helper3.func1()); | 106 Expect.equals(300, Helper3.func1()); |
| 107 } | 107 } |
| 108 } | 108 } |
| 109 | 109 |
| 110 main() { | 110 main() { |
| 111 ErrorStackTraceTest.testMain(); | 111 ErrorStackTraceTest.testMain(); |
| 112 } | 112 } |
| OLD | NEW |