implicit constructor exception_wrapper(std::exception)
authorJames Sedgwick <jsedgwick@fb.com>
Mon, 17 Nov 2014 23:04:23 +0000 (15:04 -0800)
committerDave Watson <davejwatson@fb.com>
Wed, 19 Nov 2014 20:52:34 +0000 (12:52 -0800)
Summary: this should address some of the wordiness issues with exception_wrapper, i.e. always having to use make_exception_wrapper

Test Plan: wrote a little test to make sure everything compiles (or doesn't) as expected, not worth committing

Reviewed By: davejwatson@fb.com

Subscribers: njormrod, folly-diffs@

FB internal diff: D1679460

Signature: t1:1679460:1416265170:5cd72d95dd855cd4e594dbbc49d0c53d012fbc99

folly/ExceptionWrapper.h

index d14142f0b9ec93d8b8671827748e62feef357b10..2fca5c68d26a4129458b0b77c8e2a95adad70046 100644 (file)
@@ -105,6 +105,14 @@ class exception_wrapper {
  public:
   exception_wrapper() : throwfn_(nullptr) { }
 
+  // Implicitly construct an exception_wrapper from any std::exception
+  template <typename T, typename =
+    typename std::enable_if<std::is_base_of<std::exception, T>::value>::type>
+  /* implicit */ exception_wrapper(T&& exn) {
+    item_ = std::make_shared<T>(std::forward<T>(exn));
+    throwfn_ = folly::detail::Thrower<T>::doThrow;
+  }
+
   void throwException() const {
     if (throwfn_) {
       throwfn_(item_.get());