Index: sdk/lib/io/file_impl.dart |
diff --git a/sdk/lib/io/file_impl.dart b/sdk/lib/io/file_impl.dart |
index c30d8aed3e8951e207b35194cffe490539f36e9a..dfa75f6ebd181e7fe183d530b539f0685605e00b 100644 |
--- a/sdk/lib/io/file_impl.dart |
+++ b/sdk/lib/io/file_impl.dart |
@@ -190,23 +190,26 @@ class _FileStreamConsumer extends StreamConsumer<List<int>> { |
Completer<File> completer = new Completer<File>(); |
_openFuture |
.then((openedFile) { |
+ void error(e, [StackTrace stackTrace]) { |
+ _subscription.cancel(); |
+ openedFile.close(); |
+ completer.completeError(e, stackTrace); |
+ } |
_subscription = stream.listen( |
(d) { |
_subscription.pause(); |
- openedFile.writeFrom(d, 0, d.length) |
- .then((_) => _subscription.resume()) |
- .catchError((e) { |
- openedFile.close(); |
- completer.completeError(e); |
- }); |
+ try { |
+ openedFile.writeFrom(d, 0, d.length) |
+ .then((_) => _subscription.resume(), |
+ onError: error); |
+ } catch (e, stackTrace) { |
+ error(e, stackTrace); |
+ } |
}, |
onDone: () { |
completer.complete(_file); |
}, |
- onError: (e, [StackTrace stackTrace]) { |
- openedFile.close(); |
- completer.completeError(e, stackTrace); |
- }, |
+ onError: error, |
cancelOnError: true); |
}) |
.catchError((e) { |