Fixes: prevent compiler reporting UB, hazptr_array move operator, empty array test
[folly.git] / folly / ExceptionWrapper.cpp
index 6d14f0ad31bb5b3b9d4f30bfcd2fcb61b802cd01..7cda0b7645decc3fdd2bff3eaffbc73fa8edf2b3 100644 (file)
@@ -60,6 +60,20 @@ std::exception const* get_std_exception_(std::exception_ptr eptr) noexcept {
 }
 }
 
+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) {