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

Side by Side Diff: sdk/lib/async/async_error.dart

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

Powered by Google App Engine
This is Rietveld 408576698