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

try_and_catch with no type list

Summary: Since most uses just specify `std::exception` and really just want to catch everything.

Reviewed By: ericniebler

Differential Revision: D26712827

fbshipit-source-id: b33c1a311a839a50d81b9bc6c2b441908130dec6
parent 2b8facde
......@@ -699,9 +699,20 @@ inline exception_wrapper try_and_catch_(F&& f) {
//! }
//! });
//! \endcode
template <typename... Exceptions, typename F>
template <typename Exn, typename... Exns, typename F>
exception_wrapper try_and_catch(F&& fn) {
return detail::try_and_catch_<F, Exceptions...>(std::forward<F>(fn));
return detail::try_and_catch_<F, Exn, Exns...>(std::forward<F>(fn));
}
template <typename F>
exception_wrapper try_and_catch(F&& fn) noexcept {
try {
static_cast<F&&>(fn)();
return exception_wrapper{};
} catch (std::exception const& ex) {
return exception_wrapper{std::current_exception(), ex};
} catch (...) {
return exception_wrapper{std::current_exception()};
}
}
} // namespace folly
......
......@@ -150,6 +150,11 @@ TEST(ExceptionWrapper, try_and_catch_test) {
EXPECT_THROW(
try_and_catch<std::runtime_error>([]() { throw std::exception(); }),
std::exception);
// No list
auto ew4 = try_and_catch([] { throw 17; });
EXPECT_TRUE(bool(ew4));
EXPECT_TRUE(ew4.is_compatible_with<int>());
}
TEST(ExceptionWrapper, with_exception_test) {
......
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