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

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

Issue 25027004: Add second argument to Future error handlers. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Upload 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
Index: sdk/lib/async/future.dart
diff --git a/sdk/lib/async/future.dart b/sdk/lib/async/future.dart
index 7fe2c682554ea1a264a9522c94796db4ca78e9b7..d189ef6e55ccb00a2008a82b71230e72a8d7b581 100644
--- a/sdk/lib/async/future.dart
+++ b/sdk/lib/async/future.dart
@@ -265,14 +265,19 @@ abstract class Future<T> {
* If the invoked callback returns a [Future] `f2` then `f` and `f2` are
* chained. That is, `f` is completed with the completion value of `f2`.
*
- * If [onError] is not given, it is equivalent to `(e) { throw e; }`. That
- * is, it forwards the error to `f`.
+ * The error callback [onError] must be of type `onError(error)` or
+ * `onError(error, StackTrace stackTrace)`. Depending on the function type
Lasse Reichstein Nielsen 2013/10/04 09:17:39 Per stream-comments, how about: "If [onError] is
floitsch 2013/10/05 17:22:59 Same as for Stream: * The [onError] callback mu
+ * the future either invokes [onError] with or without a stack trace. The
+ * stack trace argument might be `null` if the future itself was completed
+ * with an error but without a stack trace.
+ *
+ * If [onError] is not given it forwards the error to `f`.
*
* In most cases, it is more readable to use [catchError] separately, possibly
* with a `test` parameter, instead of handling both value and error in a
* single [then] call.
*/
- Future then(onValue(T value), { onError(Object error) });
+ Future then(onValue(T value), { Function onError });
/**
* Handles errors emitted by this [Future].
@@ -305,8 +310,11 @@ abstract class Future<T> {
* {bool test(error)}) {
* this.then((v) => v, // Forward the value.
* // But handle errors, if the [test] succeeds.
- * onError: (e) {
+ * onError: (e, stackTrace) {
* if (test == null || test(e)) {
+ * if (onError is ZoneBinaryCallback) {
+ * return onError(e, stackTrace);
+ * }
* return onError(e);
* }
* throw e;
@@ -314,7 +322,7 @@ abstract class Future<T> {
* }
*
*/
- Future catchError(onError(Object error),
+ Future catchError(Function onError,
{bool test(Object error)});
/**

Powered by Google App Engine
This is Rietveld 408576698