Allow for folly::exception_wrapper in ClientReceiveState
authorMarc Celani <marccelani@fb.com>
Wed, 7 May 2014 02:05:02 +0000 (19:05 -0700)
committerDave Watson <davejwatson@fb.com>
Tue, 20 May 2014 19:53:58 +0000 (12:53 -0700)
Summary:
This diff allows us to use folly::exception_wrapper in ClientReceiveState. Existing use cases are still supported (crs.exception() still returns an exception_ptr no matter what), but we can now choose to set an exception without throwing first.

On the folly side, add some new functions for making an exception_ptr from an exception_wrapper.

Test Plan: Reran unit tests

Reviewed By: davejwatson@fb.com

FB internal diff: D1307027

@override-unit-failures

folly/ExceptionWrapper.h

index 89ef616f1566b9122e36ca9ee5abe323abca5565..a18ee1f01b702caacccb6ab97b0d59f98e0d4166 100644 (file)
@@ -121,6 +121,14 @@ class exception_wrapper {
 
   explicit operator bool() const { return get(); }
 
+  std::exception_ptr getExceptionPtr() const {
+    try {
+      throwException();
+    } catch (...) {
+      return std::current_exception();
+    }
+  }
+
  private:
   std::shared_ptr<std::exception> item_;
   void (*throwfn_)(std::exception*);