Register singleton's destruction using std::atexit
[folly.git] / folly / ExceptionWrapper.cpp
index 205b0d78d71242c6f31e817de343fc09fab03a46..f2fa016437558dc3be01c13a29e970f272b087af 100644 (file)
@@ -58,6 +58,20 @@ std::exception const* get_std_exception_(std::exception_ptr eptr) noexcept {
     return nullptr;
   }
 }
+} // namespace
+
+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
@@ -88,4 +102,4 @@ fbstring exceptionStr(exception_wrapper const& ew) {
   return ew.what();
 }
 
-} // folly
+} // namespace folly