}
}
+exception_wrapper exception_wrapper::from_exception_ptr(
+ std::exception_ptr const& ptr) noexcept {
+ if (!ptr) {
+ return exception_wrapper();
+ }
+ try {
+ std::rethrow_exception(ptr);
+ } catch (std::exception& e) {
+ return exception_wrapper(std::current_exception(), e);
+ } catch (...) {
+ return exception_wrapper(std::current_exception());
+ }
+}
+
exception_wrapper::exception_wrapper(std::exception_ptr ptr) noexcept
: exception_wrapper{} {
if (ptr) {
static bool with_exception_(This& this_, Fn fn_);
public:
+ static exception_wrapper from_exception_ptr(
+ std::exception_ptr const& eptr) noexcept;
+
//! Default-constructs an empty `exception_wrapper`
//! \post `type() == none()`
exception_wrapper() noexcept {}
EXPECT_FALSE(eptr);
}
+TEST(ExceptionWrapper, from_exception_ptr_empty) {
+ auto ep = std::exception_ptr();
+ auto ew = exception_wrapper::from_exception_ptr(ep);
+ EXPECT_FALSE(bool(ew));
+}
+
+TEST(ExceptionWrapper, from_exception_ptr_exn) {
+ auto ep = std::make_exception_ptr(std::runtime_error("foo"));
+ auto ew = exception_wrapper::from_exception_ptr(ep);
+ EXPECT_TRUE(bool(ew));
+ EXPECT_EQ(ep, ew.to_exception_ptr());
+ EXPECT_TRUE(ew.is_compatible_with<std::runtime_error>());
+}
+
+TEST(ExceptionWrapper, from_exception_ptr_any) {
+ auto ep = std::make_exception_ptr<int>(12);
+ auto ew = exception_wrapper::from_exception_ptr(ep);
+ EXPECT_TRUE(bool(ew));
+ EXPECT_EQ(ep, ew.to_exception_ptr());
+ EXPECT_TRUE(ew.is_compatible_with<int>());
+}
+
TEST(ExceptionWrapper, with_exception_ptr_empty) {
auto ew = exception_wrapper(std::exception_ptr());
EXPECT_EQ(exception_wrapper::none(), ew.type());