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

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

Issue 555153002: Add error-intercept for Completer.completeError and StreamController.addError. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Intercept all errors thrown by unregistered callbacks. Created 6 years, 3 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/broadcast_stream_controller.dart » ('j') | no next file with comments »
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 _invokeErrorHandler(Function errorHandler, 7 _invokeErrorHandler(Function errorHandler,
8 Object error, StackTrace stackTrace) { 8 Object error, StackTrace stackTrace) {
9 if (errorHandler is ZoneBinaryCallback) { 9 if (errorHandler is ZoneBinaryCallback) {
10 return errorHandler(error, stackTrace); 10 return errorHandler(error, stackTrace);
11 } else { 11 } else {
12 return errorHandler(error); 12 return errorHandler(error);
13 } 13 }
14 } 14 }
15 15
16 Function _registerErrorHandler(Function errorHandler, Zone zone) { 16 Function _registerErrorHandler(Function errorHandler, Zone zone) {
17 if (errorHandler is ZoneBinaryCallback) { 17 if (errorHandler is ZoneBinaryCallback) {
18 return zone.registerBinaryCallback(errorHandler); 18 return zone.registerBinaryCallback(errorHandler);
19 } else { 19 } else {
20 return zone.registerUnaryCallback(errorHandler); 20 return zone.registerUnaryCallback(errorHandler);
21 } 21 }
22 } 22 }
23 23
24 class _AsyncError implements Error { 24 class _UncaughtAsyncError extends AsyncError {
25 final error;
26 final StackTrace stackTrace;
27
28 _AsyncError(this.error, this.stackTrace);
29 }
30
31 class _UncaughtAsyncError extends _AsyncError {
32 _UncaughtAsyncError(error, StackTrace stackTrace) 25 _UncaughtAsyncError(error, StackTrace stackTrace)
33 : super(error, _getBestStackTrace(error, stackTrace)); 26 : super(error, _getBestStackTrace(error, stackTrace));
34 27
35 static StackTrace _getBestStackTrace(error, StackTrace stackTrace) { 28 static StackTrace _getBestStackTrace(error, StackTrace stackTrace) {
36 if (stackTrace != null) return stackTrace; 29 if (stackTrace != null) return stackTrace;
37 if (error is Error) { 30 if (error is Error) {
38 return error.stackTrace; 31 return error.stackTrace;
39 } 32 }
40 return null; 33 return null;
41 } 34 }
42 35
43 String toString() { 36 String toString() {
44 String result = "Uncaught Error: ${error}"; 37 String result = "Uncaught Error: ${error}";
45 38
46 if (stackTrace != null) { 39 if (stackTrace != null) {
47 result += "\nStack Trace:\n$stackTrace"; 40 result += "\nStack Trace:\n$stackTrace";
48 } 41 }
49 return result; 42 return result;
50 } 43 }
51 } 44 }
OLDNEW
« no previous file with comments | « no previous file | sdk/lib/async/broadcast_stream_controller.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698