Commit e1d5ba6e authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook GitHub Bot

implement exception_wrapper::get_exception<Ex> directly

Summary: Rather than implementing it via `with_exception`, which is implemented in terms of `handle`, which is complex. Works now that exact casting can always be done without `catch`.

Reviewed By: ot, luciang

Differential Revision: D27987172

fbshipit-source-id: eca54e47b3a0fc5da4614bbd23b881b1e35eca4b
parent 9859073e
......@@ -386,16 +386,30 @@ inline std::exception const* exception_wrapper::get_exception() const noexcept {
template <typename Ex>
inline Ex* exception_wrapper::get_exception() noexcept {
Ex* object{nullptr};
with_exception([&](Ex& ex) { object = &ex; });
return object;
constexpr auto stdexcept = std::is_base_of<std::exception, Ex>::value;
if (vptr_ == &ExceptionPtr::ops_) {
return exception_ptr_get_object<Ex>(eptr_.ptr_);
} else if (!stdexcept || vptr_ == &uninit_) {
return nullptr;
} else {
using Target = conditional_t<stdexcept, Ex, std::exception>;
auto const ptr = dynamic_cast<Target*>(get_exception());
return reinterpret_cast<Ex*>(ptr);
}
}
template <typename Ex>
inline Ex const* exception_wrapper::get_exception() const noexcept {
Ex const* object{nullptr};
with_exception([&](Ex const& ex) { object = &ex; });
return object;
constexpr auto stdexcept = std::is_base_of<std::exception, Ex>::value;
if (vptr_ == &ExceptionPtr::ops_) {
return exception_ptr_get_object<Ex>(eptr_.ptr_);
} else if (!stdexcept || vptr_ == &uninit_) {
return nullptr;
} else {
using Target = conditional_t<stdexcept, Ex, std::exception>;
auto const ptr = dynamic_cast<Target const*>(get_exception());
return reinterpret_cast<Ex const*>(ptr);
}
}
inline std::exception_ptr exception_wrapper::to_exception_ptr() noexcept {
......
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