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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sdk/lib/async/async.dart ('k') | sdk/lib/async/async_sources.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 // part of dart.async;
6
7 /**
8 * Error result of an asynchronous computation.
9 */
10 class AsyncError {
11 /** The actual error thrown by the computation. */
12 final Object error;
13 /** Stack trace corresponding to the error, if available. */
14 final Object stackTrace;
15 /** Asynchronous error leading to this error, if error handling fails. */
16 final AsyncError cause;
17
18 // TODO(lrn): When possible, combine into one constructor with both optional
19 // positional and named arguments.
20 AsyncError(Object this.error, [Object this.stackTrace]): cause = null;
21 AsyncError.withCause(Object this.error, Object this.stackTrace, this.cause);
22
23 void _writeOn(StringBuffer buffer) {
24 buffer.add("'");
25 String message;
26 try {
27 message = error.toString();
28 } catch (e) {
29 message = Error.safeToString(error);
30 }
31 buffer.add(message);
32 buffer.add("'\n");
33 if (stackTrace != null) {
34 buffer.add("Stack trace:\n");
35 buffer.add(stackTrace.toString());
36 buffer.add("\n");
37 }
38 }
39
40 String toString() {
41 StringBuffer buffer = new StringBuffer();
42 buffer.add("AsyncError: ");
43 _writeOn(buffer);
44 AsyncError cause = this.cause;
45 while (cause != null) {
46 buffer.add("Caused by: ");
47 cause._writeOn(buffer);
48 cause = cause.cause;
49 }
50 return buffer.toString();
51 }
52
53 throwDelayed() {
54 reportError() {
55 print("Uncaught Error: $error");
56 if (stackTrace != null) {
57 print("Stack Trace:\n$stackTrace\n");
58 }
59 }
60
61 try {
62 new Timer(0, (_) {
63 reportError();
64 // TODO(floitsch): we potentially want to call the global error handler
65 // directly so that we can pass the stack trace.
66 throw error;
67 });
68 } catch (e) {
69 // Unfortunately there is not much more we can do...
70 reportError();
71 }
72 }
73 }
74
OLDNEW
« 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