Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(472)

Side by Side Diff: tests/language/error_stacktrace_test.dart

Issue 19106008: Fix for issue 11680 (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 ArgumentError catch (e, s) {
56 i = 200;
57 Expect.isNotNull(e.stackTrace, "Errors need a stackTrace on throw");
58 Expect.isFalse(identical(e.stackTrace, s));
59 Expect.equals(e.stackTrace.toString(), s.toString());
60 }
61 return i;
62 }
63 static List func5() {
64 // Throw an Error.
65 throw new ArgumentError("ArgumentError in func5");
66 }
67 }
68
69 class Helper3 {
70 static int func1() {
71 return func2();
72 }
73 static int func2() {
74 return func3();
75 }
76 static int func3() {
77 return func4();
78 }
79 static int func4() {
80 var i = 0;
81 try {
82 i = 10;
83 func5();
84 } on MyException catch (e) {
85 i = 300;
86 try {
87 // There should be no stackTrace in this normal excpetion object.
88 // We should get a NoSuchMethodError.
89 var trace = e.stackTrace;
90 } on NoSuchMethodError catch (e) {
91 Expect.isNotNull(e.stackTrace, "Error needs a stackTrace on throw");
92 }
93 }
94 return i;
95 }
96 static List func5() {
97 // Throw an Exception (any random object).
98 throw new MyException("MyException in func5");
99 }
100 }
101
102 class ErrorStackTraceTest {
103 static testMain() {
104 Expect.equals(100, Helper1.func1());
105 Expect.equals(200, Helper2.func1());
106 Expect.equals(300, Helper3.func1());
107 }
108 }
109
110 main() {
111 ErrorStackTraceTest.testMain();
112 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698