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

Unified Diff: lib/coreimpl/future_implementation.dart

Issue 10917053: Show nicer errors on some server failures. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 4 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: lib/coreimpl/future_implementation.dart
diff --git a/lib/coreimpl/future_implementation.dart b/lib/coreimpl/future_implementation.dart
index 328c88964c6be89f44914b7bdddb32a12102758e..999013ec5bd198180966c7a283ef84c50fcbfbb1 100644
--- a/lib/coreimpl/future_implementation.dart
+++ b/lib/coreimpl/future_implementation.dart
@@ -169,22 +169,40 @@ class FutureImpl<T> implements Future<T> {
_complete();
}
- Future transform(Function transformation) {
+ Future transform(Function transformation, [onException(Object exception)]) {
final completer = new Completer();
- handleException((e) {
- completer.completeException(e, this.stackTrace);
+
+ transformException(ex, stackTrace) {
+ var result = false;
+ if (onException != null) {
+ try {
+ result = onException(ex);
+ } catch (innerException) {
+ ex = innerException;
+ }
+ }
+
+ if (result != true) {
+ completer.completeException(ex, stackTrace);
+ }
+ }
+
+ handleException((ex) {
+ transformException(ex, this.stackTrace);
return true;
});
+
then((v) {
var transformed = null;
try {
transformed = transformation(v);
} catch (ex, stackTrace) {
- completer.completeException(ex, stackTrace);
+ transformException(ex, stackTrace);
return;
}
completer.complete(transformed);
});
+
return completer.future;
}
« no previous file with comments | « lib/core/future.dart ('k') | tests/corelib/future_test.dart » ('j') | utils/pub/io.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698