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

Side by Side Diff: sdk/lib/core/errors.dart

Issue 17580020: Revert "Make Error capture a stacktrace when it is created." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 5 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
« no previous file with comments | « no previous file | tests/co19/co19-runtime.status » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 4
5 part of dart.core; 5 part of dart.core;
6 6
7 class Error { 7 class Error {
8 final StackTrace stackTrace; 8 const Error();
9
10 Error() : stackTrace = ((){ try { throw 0; } catch (e, s) { return s; } })();
11 9
12 /** 10 /**
13 * Safely convert a value to a [String] description. 11 * Safely convert a value to a [String] description.
14 * 12 *
15 * The conversion is guaranteed to not throw, so it won't use the object's 13 * The conversion is guaranteed to not throw, so it won't use the object's
16 * toString method. 14 * toString method.
17 */ 15 */
18 static String safeToString(Object object) { 16 static String safeToString(Object object) {
19 if (object is int || object is double || object is bool || null == object) { 17 if (object is int || object is double || object is bool || null == object) {
20 return object.toString(); 18 return object.toString();
(...skipping 12 matching lines...) Expand all
33 return _objectToString(object); 31 return _objectToString(object);
34 } 32 }
35 33
36 external static String _objectToString(Object object); 34 external static String _objectToString(Object object);
37 } 35 }
38 36
39 /** 37 /**
40 * Error thrown by the runtime system when an assert statement fails. 38 * Error thrown by the runtime system when an assert statement fails.
41 */ 39 */
42 class AssertionError implements Error { 40 class AssertionError implements Error {
43 /** Assertion errors don't capture stack traces. */
44 StackTrace get stackTrace => null;
45 } 41 }
46 42
47 /** 43 /**
48 * Error thrown by the runtime system when a type assertion fails. 44 * Error thrown by the runtime system when a type assertion fails.
49 */ 45 */
50 class TypeError implements AssertionError { 46 class TypeError implements AssertionError {
51 /** Type errors don't capture stack traces. */
52 StackTrace get stackTrace => null;
53 } 47 }
54 48
55 /** 49 /**
56 * Error thrown by the runtime system when a cast operation fails. 50 * Error thrown by the runtime system when a cast operation fails.
57 */ 51 */
58 class CastError implements Error { 52 class CastError implements Error {
59 /** Cast errors don't capture stack traces. */
60 StackTrace get stackTrace => null;
61 } 53 }
62 54
63 /** 55 /**
64 * Error thrown when attempting to throw [:null:]. 56 * Error thrown when attempting to throw [:null:].
65 */ 57 */
66 class NullThrownError implements Error { 58 class NullThrownError implements Error {
67 const NullThrownError(); 59 const NullThrownError();
68 /** NullThrown errors don't capture stack traces. */
69 StackTrace get stackTrace => null;
70 String toString() => "Throw of null."; 60 String toString() => "Throw of null.";
71 } 61 }
72 62
73 /** 63 /**
74 * Error thrown when a function is passed an unacceptable argument. 64 * Error thrown when a function is passed an unacceptable argument.
75 */ 65 */
76 class ArgumentError extends Error { 66 class ArgumentError implements Error {
77 final message; 67 final message;
78 68
79 /** The [message] describes the erroneous argument. */ 69 /** The [message] describes the erroneous argument. */
80 ArgumentError([this.message]); 70 ArgumentError([this.message]);
81 71
82 String toString() { 72 String toString() {
83 if (message != null) { 73 if (message != null) {
84 return "Illegal argument(s): $message"; 74 return "Illegal argument(s): $message";
85 } 75 }
86 return "Illegal argument(s)"; 76 return "Illegal argument(s)";
(...skipping 28 matching lines...) Expand all
115 /** 105 /**
116 * Error thrown when control reaches the end of a switch case. 106 * Error thrown when control reaches the end of a switch case.
117 * 107 *
118 * The Dart specification requires this error to be thrown when 108 * The Dart specification requires this error to be thrown when
119 * control reaches the end of a switch case (except the last case 109 * control reaches the end of a switch case (except the last case
120 * of a switch) without meeting a break or similar end of the control 110 * of a switch) without meeting a break or similar end of the control
121 * flow. 111 * flow.
122 */ 112 */
123 class FallThroughError implements Error { 113 class FallThroughError implements Error {
124 const FallThroughError(); 114 const FallThroughError();
125 StackTrace get stackTrace => null;
126 } 115 }
127 116
128 // TODO(lrn): Class description. Ensure that this is the class thrown by 117
129 // both implementations, or move it to the one that uses it.
130 class AbstractClassInstantiationError implements Error { 118 class AbstractClassInstantiationError implements Error {
131 final String _className; 119 final String _className;
132 const AbstractClassInstantiationError(String this._className); 120 const AbstractClassInstantiationError(String this._className);
133 StackTrace get stackTrace => null;
134 String toString() => "Cannot instantiate abstract class: '$_className'"; 121 String toString() => "Cannot instantiate abstract class: '$_className'";
135 } 122 }
136 123
137
138 /** 124 /**
139 * Error thrown by the default implementation of [:noSuchMethod:] on [Object]. 125 * Error thrown by the default implementation of [:noSuchMethod:] on [Object].
140 */ 126 */
141 class NoSuchMethodError implements Error { 127 class NoSuchMethodError implements Error {
142 final Object _receiver; 128 final Object _receiver;
143 final String _memberName; 129 final String _memberName;
144 final List _arguments; 130 final List _arguments;
145 final Map<String,dynamic> _namedArguments; 131 final Map<String,dynamic> _namedArguments;
146 final List _existingArgumentNames; 132 final List _existingArgumentNames;
147 133
148 /** 134 /**
149 * Create a [NoSuchMethodError] corresponding to a failed method call. 135 * Create a [NoSuchMethodError] corresponding to a failed method call.
150 * 136 *
151 * The first parameter to this constructor is the receiver of the method call. 137 * The first parameter to this constructor is the receiver of the method call.
152 * That is, the object on which the method was attempted called. 138 * That is, the object on which the method was attempted called.
153 * The second parameter is the name of the called method or accessor. 139 * The second parameter is the name of the called method or accessor.
154 * The third parameter is a list of the positional arguments that the method 140 * The third parameter is a list of the positional arguments that the method
155 * was called with. 141 * was called with.
156 * The fourth parameter is a map from [String] names to the values of named 142 * The fourth parameter is a map from [String] names to the values of named
157 * arguments that the method was called with. 143 * arguments that the method was called with.
158 * The optional [exisitingArgumentNames] is the expected parameters of a 144 * The optional [exisitingArgumentNames] is the expected parameters of a
159 * method with the same name on the receiver, if available. This is 145 * method with the same name on the receiver, if available. This is
160 * the method that would have been called if the parameters had matched. 146 * the method that would have been called if the parameters had matched.
161 */ 147 */
162 NoSuchMethodError(Object this._receiver, 148 const NoSuchMethodError(Object this._receiver,
163 String this._memberName, 149 String this._memberName,
164 List this._arguments, 150 List this._arguments,
165 Map<String,dynamic> this._namedArguments, 151 Map<String,dynamic> this._namedArguments,
166 [List existingArgumentNames = null]) 152 [List existingArgumentNames = null])
167 : this._existingArgumentNames = existingArgumentNames; 153 : this._existingArgumentNames = existingArgumentNames;
168 154
169 StackTrace get stackTrace => null;
170
171 external String toString(); 155 external String toString();
172 } 156 }
173 157
174 158
175 /** 159 /**
176 * The operation was not allowed by the object. 160 * The operation was not allowed by the object.
177 * 161 *
178 * This [Error] is thrown when an instance cannot implement one of the methods 162 * This [Error] is thrown when an instance cannot implement one of the methods
179 * in its signature. 163 * in its signature.
180 */ 164 */
181 class UnsupportedError extends Error { 165 class UnsupportedError implements Error {
182 final String message; 166 final String message;
183 UnsupportedError(this.message); 167 UnsupportedError(this.message);
184 String toString() => "Unsupported operation: $message"; 168 String toString() => "Unsupported operation: $message";
185 } 169 }
186 170
187 171
188 /** 172 /**
189 * Thrown by operations that have not been implemented yet. 173 * Thrown by operations that have not been implemented yet.
190 * 174 *
191 * This [Error] is thrown by unfinished code that hasn't yet implemented 175 * This [Error] is thrown by unfinished code that hasn't yet implemented
192 * all the features it needs. 176 * all the features it needs.
193 * 177 *
194 * If a class is not intending to implement the feature, it should throw 178 * If a class is not intending to implement the feature, it should throw
195 * an [UnsupportedError] instead. This error is only intended for 179 * an [UnsupportedError] instead. This error is only intended for
196 * use during development. 180 * use during development.
197 */ 181 */
198 class UnimplementedError extends UnsupportedError { 182 class UnimplementedError implements UnsupportedError {
199 UnimplementedError([String message]) : super(message); 183 final String message;
184 UnimplementedError([String this.message]);
200 String toString() => (this.message != null 185 String toString() => (this.message != null
201 ? "UnimplementedError: $message" 186 ? "UnimplementedError: $message"
202 : "UnimplementedError"); 187 : "UnimplementedError");
203 } 188 }
204 189
205 190
206 /** 191 /**
207 * The operation was not allowed by the current state of the object. 192 * The operation was not allowed by the current state of the object.
208 * 193 *
209 * This is a generic error used for a variety of different erroneous 194 * This is a generic error used for a variety of different erroneous
210 * actions. The message should be descriptive. 195 * actions. The message should be descriptive.
211 */ 196 */
212 class StateError extends Error { 197 class StateError implements Error {
213 final String message; 198 final String message;
214 StateError(this.message); 199 StateError(this.message);
215 String toString() => "Bad state: $message"; 200 String toString() => "Bad state: $message";
216 } 201 }
217 202
218 203
219 /** 204 /**
220 * Error occurring when a collection is modified during iteration. 205 * Error occurring when a collection is modified during iteration.
221 * 206 *
222 * Some modifications may be allowed for some collections, so each collection 207 * Some modifications may be allowed for some collections, so each collection
223 * ([Iterable] or similar collection of values) should declare which operations 208 * ([Iterable] or similar collection of values) should declare which operations
224 * are allowed during an iteration. 209 * are allowed during an iteration.
225 */ 210 */
226 class ConcurrentModificationError extends Error { 211 class ConcurrentModificationError implements Error {
227 /** The object that was modified in an incompatible way. */ 212 /** The object that was modified in an incompatible way. */
228 final Object modifiedObject; 213 final Object modifiedObject;
229 214
230 ConcurrentModificationError([this.modifiedObject]); 215 const ConcurrentModificationError([this.modifiedObject]);
231 216
232 String toString() { 217 String toString() {
233 if (modifiedObject == null) { 218 if (modifiedObject == null) {
234 return "Concurrent modification during iteration."; 219 return "Concurrent modification during iteration.";
235 } 220 }
236 return "Concurrent modification during iteration: " 221 return "Concurrent modification during iteration: "
237 "${Error.safeToString(modifiedObject)}."; 222 "${Error.safeToString(modifiedObject)}.";
238 } 223 }
239 } 224 }
240 225
241 226
242 class OutOfMemoryError implements Error { 227 class OutOfMemoryError implements Error {
243 const OutOfMemoryError(); 228 const OutOfMemoryError();
244 StackTrace get stackTrace => null;
245 String toString() => "Out of Memory"; 229 String toString() => "Out of Memory";
246 } 230 }
247 231
248 232
249 class StackOverflowError implements Error { 233 class StackOverflowError implements Error {
250 const StackOverflowError(); 234 const StackOverflowError();
251 StackTrace get stackTrace => null;
252 String toString() => "Stack Overflow"; 235 String toString() => "Stack Overflow";
253 } 236 }
254 237
255 /** 238 /**
256 * Error thrown when a lazily initialized variable cannot be initialized. 239 * Error thrown when a lazily initialized variable cannot be initialized.
257 * 240 *
258 * A static/library variable with an initializer expression is initialized 241 * A static/library variable with an initializer expression is initialized
259 * the first time it is read. If evaluating the initializer expression causes 242 * the first time it is read. If evaluating the initializer expression causes
260 * another read of the variable, this error is thrown. 243 * another read of the variable, this error is thrown.
261 */ 244 */
262 class CyclicInitializationError implements Error { 245 class CyclicInitializationError implements Error {
263 final String variableName; 246 final String variableName;
264 const CyclicInitializationError([this.variableName]); 247 const CyclicInitializationError([this.variableName]);
265 StackTrace get stackTrace => null;
266 String toString() => variableName == null 248 String toString() => variableName == null
267 ? "Reading static variable during its initialization" 249 ? "Reading static variable during its initialization"
268 : "Reading static variable '$variableName' during its initialization"; 250 : "Reading static variable '$variableName' during its initialization";
269 } 251 }
OLDNEW
« no previous file with comments | « no previous file | tests/co19/co19-runtime.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698