X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=folly%2FExceptionWrapper.h;h=82dfde723ee71cf8d66e3cae3907a5d0650b2f53;hb=b3e7df8220f410398011fea71b280ba8be459fcc;hp=dcdf862870863c25585415d15497505f01c4f5fc;hpb=3a7cbbe49433606c07f53a32cca05d7cb221e433;p=folly.git diff --git a/folly/ExceptionWrapper.h b/folly/ExceptionWrapper.h index dcdf8628..82dfde72 100644 --- a/folly/ExceptionWrapper.h +++ b/folly/ExceptionWrapper.h @@ -137,7 +137,7 @@ auto fold(Fn&& fn, A&& a, B&& b, Bs&&... bs) { //! // Thread2: Exceptions are ok! //! void processResult() { //! try { -//! globalExceptionWrapper.throwException(); +//! globalExceptionWrapper.throw_exception(); //! } catch (const FacePlantException& e) { //! LOG(ERROR) << "FACEPLANT!"; //! } catch (const FailWhaleException& e) { @@ -203,14 +203,7 @@ class exception_wrapper final { static std::type_info const* uninit_type_(exception_wrapper const*); - static constexpr VTable const uninit_{ - &noop_, - &noop_, - &noop_, - &noop_, - &uninit_type_, - &noop_, - &noop_}; + static VTable const uninit_; template using IsStdException = std::is_base_of>>; @@ -277,13 +270,7 @@ class exception_wrapper final { static std::type_info const* type_(exception_wrapper const* that); static std::exception const* get_exception_(exception_wrapper const* that); static exception_wrapper get_exception_ptr_(exception_wrapper const* that); - static constexpr VTable const ops_{copy_, - move_, - delete_, - throw_, - type_, - get_exception_, - get_exception_ptr_}; + static VTable const ops_; }; template @@ -334,13 +321,7 @@ class exception_wrapper final { static std::type_info const* type_(exception_wrapper const* that); static std::exception const* get_exception_(exception_wrapper const* that); static exception_wrapper get_exception_ptr_(exception_wrapper const* that); - static constexpr VTable ops_{copy_, - move_, - delete_, - throw_, - type_, - get_exception_, - get_exception_ptr_}; + static VTable const ops_; }; union { @@ -433,7 +414,7 @@ class exception_wrapper final { class Ex, class Ex_ = _t>, FOLLY_REQUIRES( - Conjunction, IsRegularExceptionType>())> + Conjunction, IsRegularExceptionType>::value)> /* implicit */ exception_wrapper(Ex&& ex); //! \pre `typeid(ex) == typeid(typename decay::type)` @@ -446,7 +427,7 @@ class exception_wrapper final { template < class Ex, class Ex_ = _t>, - FOLLY_REQUIRES(IsRegularExceptionType())> + FOLLY_REQUIRES(IsRegularExceptionType::value)> exception_wrapper(in_place_t, Ex&& ex); //! Swaps the value of `*this` with the value of `that` @@ -476,6 +457,18 @@ class exception_wrapper final { //! \overload std::exception const* get_exception() const noexcept; + //! \returns a pointer to the `Ex` held by `*this`, if it holds an object + //! whose type `From` permits `std::is_convertible`; + //! otherwise, returns `nullptr`. + //! \note This function does not mutate the `exception_wrapper` object. + //! \note This function may cause an exception to be thrown and immediately + //! caught internally, affecting runtime performance. + template + Ex* get_object() noexcept; + //! \overload + template + Ex const* get_object() const noexcept; + //! \return A `std::exception_ptr` that references either the exception held //! by `*this`, or a copy of same. //! \note This function may need to throw an exception to complete the action. @@ -518,7 +511,12 @@ class exception_wrapper final { //! \pre `bool(*this)` //! Throws the wrapped expression. - [[noreturn]] void throwException() const; + [[noreturn]] void throw_exception() const; + + [[noreturn]] FOLLY_DEPRECATED( + "use throw_exception") void throwException() const { + throw_exception(); + } //! Call `fn` with the wrapped exception (if any), if `fn` can accept it. //! \par Example @@ -561,7 +559,7 @@ class exception_wrapper final { //! ew.handle( //! [&](std::logic_error const& e) { //! LOG(DFATAL) << "ruh roh"; - //! ew.throwException(); // rethrow the active exception without + //! ew.throw_exception(); // rethrow the active exception without //! // slicing it. Will not be caught by other //! // handlers in this call. //! }, @@ -653,7 +651,7 @@ inline exception_wrapper try_and_catch_(F&& f) { //! //! \par Example Usage: //! \code -//! // This catches my runtime_error and if I call throwException() on ew, it +//! // This catches my runtime_error and if I call throw_exception() on ew, it //! // will throw a runtime_error //! auto ew = folly::try_and_catch([=]() { //! if (badThingHappens()) { @@ -661,7 +659,7 @@ inline exception_wrapper try_and_catch_(F&& f) { //! } //! }); //! -//! // This will catch the exception and if I call throwException() on ew, it +//! // This will catch the exception and if I call throw_exception() on ew, it //! // will throw a std::exception //! auto ew = folly::try_and_catch([=]() { //! if (badThingHappens()) {