Commit 1d883868 authored by Eric Niebler's avatar Eric Niebler Committed by Facebook Github Bot

don't slice std:: exceptions in exception_wrapper::handle when no handler is found

Summary:
Given an exception_wrapper `ew` holding a `std::runtime_error`, the following assertion fails:

```
try {
  ew.handle();
} catch( std::runtime_error const & ) {
} catch( std::exception const & ) {
  assert(false);
}
```

Reviewed By: simpkins

Differential Revision: D9199924

fbshipit-source-id: b6f90ccf269a1b58f0dd07723451ff34cde1d529
parent be5070bf
......@@ -606,8 +606,8 @@ inline void exception_wrapper::handle_(
// This continuation gets evaluated if CatchFns... does not include a
// catch-all handler. It is a no-op.
auto continuation = [](StdEx* ex) { return ex; };
if (StdEx* e = impl(continuation)) {
throw *e; // Not handled. Throw.
if (nullptr != impl(continuation)) {
this_.throw_exception();
}
}
......
......@@ -636,6 +636,37 @@ TEST(ExceptionWrapper, handle_std_exception_unhandled) {
EXPECT_TRUE(handled);
}
TEST(ExceptionWrapper, handle_std_exception_propagated) {
auto ep = std::make_exception_ptr(std::runtime_error{"hello world"});
exception_wrapper const ew_eptr(ep, from_eptr<std::runtime_error>(ep));
exception_wrapper const ew_small(std::runtime_error{"hello world"});
exception_wrapper const ew_big(BigRuntimeError{"hello world"});
try {
ew_eptr.handle();
} catch (const std::runtime_error&) {
SUCCEED();
} catch (const std::exception&) {
ADD_FAILURE();
}
try {
ew_small.handle();
} catch (const std::runtime_error&) {
SUCCEED();
} catch (const std::exception&) {
ADD_FAILURE();
}
try {
ew_big.handle();
} catch (const std::runtime_error&) {
SUCCEED();
} catch (const std::exception&) {
ADD_FAILURE();
}
}
TEST(ExceptionWrapper, handle_non_std_exception_small) {
auto ep = std::make_exception_ptr(42);
exception_wrapper const ew_eptr1(ep);
......
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