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

Unified Diff: sdk/lib/core/errors.dart

Issue 18259021: Introduce StackTraceOnThrowMixin. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sdk/lib/_internal/lib/js_helper.dart ('k') | sdk/lib/json/json.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/core/errors.dart
diff --git a/sdk/lib/core/errors.dart b/sdk/lib/core/errors.dart
index f61cdfe07f815bcdc596f8851d782cd77d486edc..6f01ce0c5de1d447c422631515e85a8ee1012fca 100644
--- a/sdk/lib/core/errors.dart
+++ b/sdk/lib/core/errors.dart
@@ -5,6 +5,8 @@
part of dart.core;
class Error {
+ const Error();
+
/**
* Safely convert a value to a [String] description.
*
@@ -31,13 +33,33 @@ class Error {
external static String _objectToString(Object object);
+ /**
+ * The stack trace of `this` error. May be null.
+ */
+ StackTrace get stackTrace => null;
+}
+
+/**
+ * Captures the stack trace when thrown.
+ */
+class StackTraceOnThrow {
+ /**
+ * Captures the current stack-trace when thrown.
+ *
+ * Classes extending or mixing-in this class will automatically have a stack
+ * trace captured the first time they are thrown. This stack trace is returned
+ * by the [stackTrace] getter.
+ *
+ * Throwing the object again will not cause overwrite the first stack trace,
+ * so bjects that are `StackTraceOnThrow` instances should not be reused.
+ */
external StackTrace get stackTrace;
}
/**
* Error thrown by the runtime system when an assert statement fails.
*/
-class AssertionError extends Error {
+class AssertionError extends Error with StackTraceOnThrow {
}
/**
@@ -49,13 +71,13 @@ class TypeError extends AssertionError {
/**
* Error thrown by the runtime system when a cast operation fails.
*/
-class CastError extends Error {
+class CastError extends Error with StackTraceOnThrow {
}
/**
* Error thrown when attempting to throw [:null:].
*/
-class NullThrownError extends Error {
+class NullThrownError extends Error with StackTraceOnThrow {
NullThrownError();
String toString() => "Throw of null.";
}
@@ -63,7 +85,7 @@ class NullThrownError extends Error {
/**
* Error thrown when a function is passed an unacceptable argument.
*/
-class ArgumentError extends Error {
+class ArgumentError extends Error with StackTraceOnThrow {
final message;
/** The [message] describes the erroneous argument. */
@@ -110,12 +132,12 @@ class RangeError extends ArgumentError {
* of a switch) without meeting a break or similar end of the control
* flow.
*/
-class FallThroughError extends Error {
- FallThroughError();
+class FallThroughError extends Error with StackTraceOnThrow {
}
-class AbstractClassInstantiationError extends Error {
+class AbstractClassInstantiationError
+ extends Error with StackTraceOnThrow {
final String _className;
AbstractClassInstantiationError(String this._className);
String toString() => "Cannot instantiate abstract class: '$_className'";
@@ -124,7 +146,7 @@ class AbstractClassInstantiationError extends Error {
/**
* Error thrown by the default implementation of [:noSuchMethod:] on [Object].
*/
-class NoSuchMethodError extends Error {
+class NoSuchMethodError extends Error with StackTraceOnThrow {
final Object _receiver;
final String _memberName;
final List _arguments;
@@ -162,7 +184,7 @@ class NoSuchMethodError extends Error {
* This [Error] is thrown when an instance cannot implement one of the methods
* in its signature.
*/
-class UnsupportedError extends Error {
+class UnsupportedError extends Error with StackTraceOnThrow {
final String message;
UnsupportedError(this.message);
String toString() => "Unsupported operation: $message";
@@ -179,7 +201,8 @@ class UnsupportedError extends Error {
* an [UnsupportedError] instead. This error is only intended for
* use during development.
*/
-class UnimplementedError extends Error implements UnsupportedError {
+class UnimplementedError
+ extends Error with StackTraceOnThrow implements UnsupportedError {
final String message;
UnimplementedError([String this.message]);
String toString() => (this.message != null
@@ -194,7 +217,7 @@ class UnimplementedError extends Error implements UnsupportedError {
* This is a generic error used for a variety of different erroneous
* actions. The message should be descriptive.
*/
-class StateError extends Error {
+class StateError extends Error with StackTraceOnThrow {
final String message;
StateError(this.message);
String toString() => "Bad state: $message";
@@ -208,7 +231,7 @@ class StateError extends Error {
* ([Iterable] or similar collection of values) should declare which operations
* are allowed during an iteration.
*/
-class ConcurrentModificationError extends Error {
+class ConcurrentModificationError extends Error with StackTraceOnThrow {
/** The object that was modified in an incompatible way. */
final Object modifiedObject;
@@ -224,19 +247,15 @@ class ConcurrentModificationError extends Error {
}
-class OutOfMemoryError implements Error {
+class OutOfMemoryError extends Error {
const OutOfMemoryError();
String toString() => "Out of Memory";
-
- StackTrace get stackTrace => null;
}
-class StackOverflowError implements Error {
+class StackOverflowError extends Error {
const StackOverflowError();
String toString() => "Stack Overflow";
-
- StackTrace get stackTrace => null;
}
/**
@@ -246,7 +265,7 @@ class StackOverflowError implements Error {
* the first time it is read. If evaluating the initializer expression causes
* another read of the variable, this error is thrown.
*/
-class CyclicInitializationError extends Error {
+class CyclicInitializationError extends Error with StackTraceOnThrow {
final String variableName;
CyclicInitializationError([this.variableName]);
String toString() => variableName == null
« no previous file with comments | « sdk/lib/_internal/lib/js_helper.dart ('k') | sdk/lib/json/json.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698