From a575384b0cf738445a856c5f6fad439224d81c76 Mon Sep 17 00:00:00 2001 From: James Sedgwick Date: Mon, 17 Nov 2014 15:04:23 -0800 Subject: [PATCH] implicit constructor exception_wrapper(std::exception) 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 | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/folly/ExceptionWrapper.h b/folly/ExceptionWrapper.h index d14142f0..2fca5c68 100644 --- a/folly/ExceptionWrapper.h +++ b/folly/ExceptionWrapper.h @@ -105,6 +105,14 @@ class exception_wrapper { public: exception_wrapper() : throwfn_(nullptr) { } + // Implicitly construct an exception_wrapper from any std::exception + template ::value>::type> + /* implicit */ exception_wrapper(T&& exn) { + item_ = std::make_shared(std::forward(exn)); + throwfn_ = folly::detail::Thrower::doThrow; + } + void throwException() const { if (throwfn_) { throwfn_(item_.get()); -- 2.34.1