Chromium Code Reviews| Index: sdk/lib/core/errors.dart |
| diff --git a/sdk/lib/core/errors.dart b/sdk/lib/core/errors.dart |
| index f61cdfe07f815bcdc596f8851d782cd77d486edc..81b845a42335d1007b2427b9c8382039a41c5013 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,31 +33,44 @@ 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. |
|
Lasse Reichstein Nielsen
2013/07/12 13:00:51
Captures the current stack-trace when thrown.
Cla
floitsch
2013/07/12 15:30:14
Done.
|
| + */ |
| +class StackTraceOnThrowMixin { |
| + /** |
| + * The stack trace is automatically set the first time an instance is thrown. |
| + */ |
| external StackTrace get stackTrace; |
| } |
| /** |
| * Error thrown by the runtime system when an assert statement fails. |
| */ |
| -class AssertionError extends Error { |
| +class AssertionError extends Error with StackTraceOnThrowMixin { |
| } |
| /** |
| * Error thrown by the runtime system when a type assertion fails. |
| */ |
| -class TypeError extends AssertionError { |
| +class TypeError extends AssertionError with StackTraceOnThrowMixin { |
|
Lasse Reichstein Nielsen
2013/07/12 13:00:51
Not necessary, it extends AssertionError.
floitsch
2013/07/12 15:30:14
Done.
|
| } |
| /** |
| * Error thrown by the runtime system when a cast operation fails. |
| */ |
| -class CastError extends Error { |
| +class CastError extends Error with StackTraceOnThrowMixin { |
| } |
| /** |
| * Error thrown when attempting to throw [:null:]. |
| */ |
| -class NullThrownError extends Error { |
| +class NullThrownError extends Error with StackTraceOnThrowMixin { |
| NullThrownError(); |
| String toString() => "Throw of null."; |
| } |
| @@ -63,7 +78,7 @@ class NullThrownError extends Error { |
| /** |
| * Error thrown when a function is passed an unacceptable argument. |
| */ |
| -class ArgumentError extends Error { |
| +class ArgumentError extends Error with StackTraceOnThrowMixin { |
| final message; |
| /** The [message] describes the erroneous argument. */ |
| @@ -110,12 +125,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 StackTraceOnThrowMixin { |
| } |
| -class AbstractClassInstantiationError extends Error { |
| +class AbstractClassInstantiationError |
| + extends Error with StackTraceOnThrowMixin { |
| final String _className; |
| AbstractClassInstantiationError(String this._className); |
| String toString() => "Cannot instantiate abstract class: '$_className'"; |
| @@ -124,7 +139,7 @@ class AbstractClassInstantiationError extends Error { |
| /** |
| * Error thrown by the default implementation of [:noSuchMethod:] on [Object]. |
| */ |
| -class NoSuchMethodError extends Error { |
| +class NoSuchMethodError extends Error with StackTraceOnThrowMixin { |
| final Object _receiver; |
| final String _memberName; |
| final List _arguments; |
| @@ -162,7 +177,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 StackTraceOnThrowMixin { |
| final String message; |
| UnsupportedError(this.message); |
| String toString() => "Unsupported operation: $message"; |
| @@ -179,7 +194,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 StackTraceOnThrowMixin implements UnsupportedError { |
| final String message; |
| UnimplementedError([String this.message]); |
| String toString() => (this.message != null |
| @@ -194,7 +210,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 StackTraceOnThrowMixin { |
| final String message; |
| StateError(this.message); |
| String toString() => "Bad state: $message"; |
| @@ -208,7 +224,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 StackTraceOnThrowMixin { |
| /** The object that was modified in an incompatible way. */ |
| final Object modifiedObject; |
| @@ -224,19 +240,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 +258,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 StackTraceOnThrowMixin { |
| final String variableName; |
| CyclicInitializationError([this.variableName]); |
| String toString() => variableName == null |