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

Unified Diff: sdk/lib/async/async_error.dart

Issue 25027004: Add second argument to Future error handlers. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 7 years, 2 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/pub/lib/src/error_group.dart ('k') | sdk/lib/async/future.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/async/async_error.dart
diff --git a/sdk/lib/async/async_error.dart b/sdk/lib/async/async_error.dart
index 05fbb88b211b769782bcc8d43639fdbc52ff98c5..d5732165b2b1f026de27c4633b9de972d35c5c69 100644
--- a/sdk/lib/async/async_error.dart
+++ b/sdk/lib/async/async_error.dart
@@ -11,6 +11,23 @@ void _attachStackTrace(o, st) {
_stackTraceExpando[o] = st;
}
+_invokeErrorHandler(Function errorHandler,
+ Object error, StackTrace stackTrace) {
+ if (errorHandler is ZoneBinaryCallback) {
+ return errorHandler(error, stackTrace);
+ } else {
+ return errorHandler(error);
+ }
+}
+
+Function _registerErrorHandler(Function errorHandler, Zone zone) {
+ if (errorHandler is ZoneBinaryCallback) {
+ return zone.registerBinaryCallback(errorHandler);
+ } else {
+ return zone.registerUnaryCallback(errorHandler);
+ }
+}
+
/**
* *This is an experimental API.*
*
@@ -25,3 +42,38 @@ getAttachedStackTrace(o) {
if (o == null || o is bool || o is num || o is String) return null;
return _stackTraceExpando[o];
}
+
+class _AsyncError implements Error {
+ final error;
+ final StackTrace stackTrace;
+
+ _AsyncError(this.error, this.stackTrace);
+}
+
+class _UncaughtAsyncError extends _AsyncError {
+ _UncaughtAsyncError(error, StackTrace stackTrace)
+ : super(error, _getBestStackTrace(error, stackTrace)) {
+ // Clear the attached stack trace.
+ _attachStackTrace(error, null);
+ }
+
+ static StackTrace _getBestStackTrace(error, StackTrace stackTrace) {
+ if (stackTrace != null) return stackTrace;
+ var trace = getAttachedStackTrace(error);
+ if (trace != null) return trace;
+ if (error is Error) {
+ Error e = error;
+ return e.stackTrace;
+ }
+ return null;
+ }
+
+ String toString() {
+ String result = "Uncaught Error: ${error}";
+
+ if (stackTrace != null) {
+ result += "\nStack Trace:\n$stackTrace";
+ }
+ return result;
+ }
+}
« no previous file with comments | « sdk/lib/_internal/pub/lib/src/error_group.dart ('k') | sdk/lib/async/future.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698