Skip to content

Commit 2374654

Browse files
committed
Preserve the stack trace for rethrown exceptions in Future.transformException.
Review URL: https://codereview.chromium.org//11308281 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@15704 260f80e4-7a28-3924-810f-c04153c831b5
1 parent 5cb6cb0 commit 2374654

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

sdk/lib/core/future_impl.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,11 @@ class _FutureImpl<T> implements Future<T> {
235235
completer.complete(result);
236236
}
237237
} catch (innerException, stackTrace) {
238-
completer.completeException(innerException, stackTrace);
238+
if (identical(ex, innerException)) {
239+
completer.completeException(innerException, this.stackTrace);
240+
} else {
241+
completer.completeException(innerException, stackTrace);
242+
}
239243
}
240244
return false;
241245
});

tests/corelib/future_test.dart

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,19 @@ testCallStackIsCapturedIfChainCallbackThrows() {
351351
Expect.isNotNull(chained.stackTrace);
352352
}
353353

354+
testCallStackIsPreservedIfExceptionIsRethrownInTransformException() {
355+
final completer = new Completer();
356+
var chained = completer.future.chain((_) {
357+
throw 'whoops!';
358+
});
359+
var transformed = chained.transformException((e) {
360+
throw e;
361+
});
362+
363+
completer.complete('blah');
364+
Expect.equals(transformed.stackTrace, chained.stackTrace);
365+
}
366+
354367
// Tests for mixed usage of [onComplete], [then], and [handleException]
355368

356369
testCompleteWithCompletionAndSuccessHandlers() {
@@ -677,6 +690,7 @@ main() {
677690
testCallStackReturnsCallstackPassedToCompleteException();
678691
testCallStackIsCapturedIfTransformCallbackThrows();
679692
testCallStackIsCapturedIfChainCallbackThrows();
693+
testCallStackIsPreservedIfExceptionIsRethrownInTransformException();
680694
testCompleteWithCompletionAndSuccessHandlers();
681695
testExceptionWithCompletionAndSuccessHandlers();
682696
testExceptionWithCompletionAndSuccessAndExceptionHandlers();

0 commit comments

Comments
 (0)