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 { ...@@ -356,6 +356,7 @@ class Core final {
} }
if (x) { if (x) {
exception_wrapper ew;
try { try {
if (LIKELY(x->getNumPriorities() == 1)) { if (LIKELY(x->getNumPriorities() == 1)) {
x->add([core_ref = CountedReference(this)]() mutable { x->add([core_ref = CountedReference(this)]() mutable {
...@@ -374,10 +375,15 @@ class Core final { ...@@ -374,10 +375,15 @@ class Core final {
core->callback_(std::move(*core->result_)); core->callback_(std::move(*core->result_));
}, priority); }, priority);
} }
} catch (const std::exception& e) {
ew = exception_wrapper(std::current_exception(), e);
} catch (...) { } catch (...) {
ew = exception_wrapper(std::current_exception());
}
if (ew) {
CountedReference core_ref(this); CountedReference core_ref(this);
RequestContextScopeGuard rctx(context_); RequestContextScopeGuard rctx(context_);
result_ = Try<T>(exception_wrapper(std::current_exception())); result_ = Try<T>(std::move(ew));
SCOPE_EXIT { callback_ = {}; }; SCOPE_EXIT { callback_ = {}; };
callback_(std::move(*result_)); callback_(std::move(*result_));
} }
......
...@@ -92,6 +92,8 @@ TEST(Promise, setException) { ...@@ -92,6 +92,8 @@ TEST(Promise, setException) {
auto f = p.getFuture(); auto f = p.getFuture();
try { try {
throw eggs; throw eggs;
} catch (const std::exception& e) {
p.setException(exception_wrapper(std::current_exception(), e));
} catch (...) { } catch (...) {
p.setException(exception_wrapper(std::current_exception())); p.setException(exception_wrapper(std::current_exception()));
} }
......
...@@ -146,8 +146,8 @@ TEST(SharedPromise, splitFutureFailure) { ...@@ -146,8 +146,8 @@ TEST(SharedPromise, splitFutureFailure) {
EXPECT_FALSE(f1.isReady()); EXPECT_FALSE(f1.isReady());
try { try {
throw std::runtime_error("Oops"); throw std::runtime_error("Oops");
} catch (...) { } catch (const std::exception& e) {
p.setException(exception_wrapper(std::current_exception())); p.setException(exception_wrapper(std::current_exception(), e));
} }
EXPECT_TRUE(f1.isReady()); EXPECT_TRUE(f1.isReady());
EXPECT_TRUE(f1.hasException()); 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