//! // Thread2: Exceptions are ok!
//! void processResult() {
//! try {
-//! globalExceptionWrapper.throwException();
+//! globalExceptionWrapper.throw_exception();
//! } catch (const FacePlantException& e) {
//! LOG(ERROR) << "FACEPLANT!";
//! } catch (const FailWhaleException& e) {
class Ex,
class Ex_ = _t<std::decay<Ex>>,
FOLLY_REQUIRES(
- Conjunction<IsStdException<Ex_>, IsRegularExceptionType<Ex_>>())>
+ Conjunction<IsStdException<Ex_>, IsRegularExceptionType<Ex_>>::value)>
/* implicit */ exception_wrapper(Ex&& ex);
//! \pre `typeid(ex) == typeid(typename decay<Ex>::type)`
template <
class Ex,
class Ex_ = _t<std::decay<Ex>>,
- FOLLY_REQUIRES(IsRegularExceptionType<Ex_>())>
+ FOLLY_REQUIRES(IsRegularExceptionType<Ex_>::value)>
exception_wrapper(in_place_t, Ex&& ex);
//! Swaps the value of `*this` with the value of `that`
//! \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<From*, Ex*>`;
+ //! 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 <typename Ex>
+ Ex* get_exception() noexcept;
+ //! \overload
+ template <typename Ex>
+ Ex const* get_exception() 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.
//! \pre `bool(*this)`
//! Throws the wrapped expression.
- [[noreturn]] void throwException() const;
+ [[noreturn]] void throw_exception() const;
//! Call `fn` with the wrapped exception (if any), if `fn` can accept it.
//! \par Example
//! 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.
//! },
//!
//! \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<std::exception, std::runtime_error>([=]() {
//! if (badThingHappens()) {
//! }
//! });
//!
-//! // 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<std::exception, std::runtime_error>([=]() {
//! if (badThingHappens()) {