Commit 0e7c824d authored by Eric Niebler's avatar Eric Niebler Committed by Facebook Github Bot

capture exception information when creating exception_wrapper

Summary:
prefer creating an exception_wrapper with a reference to the active exception

Depends on D4410421

Reviewed By: spacedentist

Differential Revision: D4410455

fbshipit-source-id: d6b6aeb5fa72782e31d754a0b853514af5fdb8cd
parent 1e531547
......@@ -356,6 +356,7 @@ class Core final {
}
if (x) {
exception_wrapper ew;
try {
if (LIKELY(x->getNumPriorities() == 1)) {
x->add([core_ref = CountedReference(this)]() mutable {
......@@ -374,10 +375,15 @@ class Core final {
core->callback_(std::move(*core->result_));
}, priority);
}
} catch (const std::exception& e) {
ew = exception_wrapper(std::current_exception(), e);
} catch (...) {
ew = exception_wrapper(std::current_exception());
}
if (ew) {
CountedReference core_ref(this);
RequestContextScopeGuard rctx(context_);
result_ = Try<T>(exception_wrapper(std::current_exception()));
result_ = Try<T>(std::move(ew));
SCOPE_EXIT { callback_ = {}; };
callback_(std::move(*result_));
}
......
......@@ -92,6 +92,8 @@ TEST(Promise, setException) {
auto f = p.getFuture();
try {
throw eggs;
} catch (const std::exception& e) {
p.setException(exception_wrapper(std::current_exception(), e));
} catch (...) {
p.setException(exception_wrapper(std::current_exception()));
}
......
......@@ -146,8 +146,8 @@ TEST(SharedPromise, splitFutureFailure) {
EXPECT_FALSE(f1.isReady());
try {
throw std::runtime_error("Oops");
} catch (...) {
p.setException(exception_wrapper(std::current_exception()));
} catch (const std::exception& e) {
p.setException(exception_wrapper(std::current_exception(), e));
}
EXPECT_TRUE(f1.isReady());
EXPECT_TRUE(f1.hasException());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment