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

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

Issue 11783009: Big merge from experimental to bleeding edge. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 11 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/async/async.dart ('k') | sdk/lib/async/async_sources.gypi » ('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
new file mode 100644
index 0000000000000000000000000000000000000000..aad80b7f8b5a2c818e954ca4c49cf75f45c3f0f6
--- /dev/null
+++ b/sdk/lib/async/async_error.dart
@@ -0,0 +1,74 @@
+// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+// part of dart.async;
+
+/**
+ * Error result of an asynchronous computation.
+ */
+class AsyncError {
+ /** The actual error thrown by the computation. */
+ final Object error;
+ /** Stack trace corresponding to the error, if available. */
+ final Object stackTrace;
+ /** Asynchronous error leading to this error, if error handling fails. */
+ final AsyncError cause;
+
+ // TODO(lrn): When possible, combine into one constructor with both optional
+ // positional and named arguments.
+ AsyncError(Object this.error, [Object this.stackTrace]): cause = null;
+ AsyncError.withCause(Object this.error, Object this.stackTrace, this.cause);
+
+ void _writeOn(StringBuffer buffer) {
+ buffer.add("'");
+ String message;
+ try {
+ message = error.toString();
+ } catch (e) {
+ message = Error.safeToString(error);
+ }
+ buffer.add(message);
+ buffer.add("'\n");
+ if (stackTrace != null) {
+ buffer.add("Stack trace:\n");
+ buffer.add(stackTrace.toString());
+ buffer.add("\n");
+ }
+ }
+
+ String toString() {
+ StringBuffer buffer = new StringBuffer();
+ buffer.add("AsyncError: ");
+ _writeOn(buffer);
+ AsyncError cause = this.cause;
+ while (cause != null) {
+ buffer.add("Caused by: ");
+ cause._writeOn(buffer);
+ cause = cause.cause;
+ }
+ return buffer.toString();
+ }
+
+ throwDelayed() {
+ reportError() {
+ print("Uncaught Error: $error");
+ if (stackTrace != null) {
+ print("Stack Trace:\n$stackTrace\n");
+ }
+ }
+
+ try {
+ new Timer(0, (_) {
+ reportError();
+ // TODO(floitsch): we potentially want to call the global error handler
+ // directly so that we can pass the stack trace.
+ throw error;
+ });
+ } catch (e) {
+ // Unfortunately there is not much more we can do...
+ reportError();
+ }
+ }
+}
+
« no previous file with comments | « sdk/lib/async/async.dart ('k') | sdk/lib/async/async_sources.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698