proxygen
|
#include <ExceptionWrapper.h>
Classes | |
struct | AnyException |
struct | arg_type_ |
struct | arg_type_< Ret(*)(...)> |
struct | arg_type_< Ret(*)(Arg)> |
struct | arg_type_< Ret(...)> |
struct | arg_type_< Ret(Arg)> |
struct | arg_type_< Ret(Class::*)(...) const > |
struct | arg_type_< Ret(Class::*)(...)> |
struct | arg_type_< Ret(Class::*)(Arg) const > |
struct | arg_type_< Ret(Class::*)(Arg)> |
struct | Buffer |
struct | ExceptionPtr |
struct | ExceptionTypeOf |
struct | HandleReduce |
struct | HandleStdExceptReduce |
struct | InPlace |
struct | InSituTag |
struct | IsRegularExceptionType |
struct | OnHeapTag |
struct | SharedPtr |
struct | ThrownTag |
struct | Unknown |
struct | VTable |
Public Member Functions | |
exception_wrapper () noexcept | |
exception_wrapper (exception_wrapper &&that) noexcept | |
exception_wrapper (exception_wrapper const &that) noexcept | |
exception_wrapper & | operator= (exception_wrapper &&that) noexcept |
exception_wrapper & | operator= (exception_wrapper const &that) noexcept |
~exception_wrapper () | |
exception_wrapper (std::exception_ptr ptr) noexcept | |
template<class Ex > | |
exception_wrapper (std::exception_ptr ptr, Ex &ex) noexcept | |
template<class Ex , class Ex_ = _t<std::decay<Ex>>> | |
exception_wrapper (Ex &&ex) | |
template<class Ex , class Ex_ = _t<std::decay<Ex>>, _t< std::enable_if< static_cast< bool >(IsRegularExceptionType< Ex_ >::value), long >> = __LINE__> | |
exception_wrapper (in_place_t, Ex &&ex) | |
template<class Ex , typename... As, _t< std::enable_if< static_cast< bool >(IsRegularExceptionType< Ex >::value), long >> = __LINE__> | |
exception_wrapper (in_place_type_t< Ex >, As &&...as) | |
void | swap (exception_wrapper &that) noexcept |
Swaps the value of *this with the value of that More... | |
operator bool () const noexcept | |
bool | operator! () const noexcept |
void | reset () |
bool | has_exception_ptr () const noexcept |
std::exception * | get_exception () noexcept |
std::exception const * | get_exception () const noexcept |
template<typename Ex > | |
Ex * | get_exception () noexcept |
template<typename Ex > | |
Ex const * | get_exception () const noexcept |
std::exception_ptr const & | to_exception_ptr () noexcept |
std::exception_ptr | to_exception_ptr () const noexcept |
std::type_info const & | type () const noexcept |
folly::fbstring | what () const |
folly::fbstring | class_name () const |
template<class Ex > | |
bool | is_compatible_with () const noexcept |
void | throw_exception () const |
template<class Ex > | |
void | throw_with_nested (Ex &&ex) const |
template<class Ex = void const, class Fn > | |
bool | with_exception (Fn fn) |
template<class Ex = void const, class Fn > | |
bool | with_exception (Fn fn) const |
template<class... CatchFns> | |
void | handle (CatchFns...fns) |
template<class... CatchFns> | |
void | handle (CatchFns...fns) const |
template<class Ex , class Ex_, FOLLY_REQUIRES_DEF(Conjunction< exception_wrapper::IsStdException< Ex_ >,exception_wrapper::IsRegularExceptionType< Ex_ >>::value) > | |
exception_wrapper (Ex &&ex) | |
Static Public Member Functions | |
static exception_wrapper | from_exception_ptr (std::exception_ptr const &eptr) noexcept |
static std::type_info const & | none () noexcept |
static std::type_info const & | unknown () noexcept |
Private Types | |
template<class Fn > | |
using | arg_type = _t< arg_type_< Fn >> |
template<class Ex > | |
using | IsStdException = std::is_base_of< std::exception, _t< std::decay< Ex >>> |
template<bool B, class T > | |
using | AddConstIf = exception_wrapper_detail::AddConstIf< B, T > |
template<class CatchFn > | |
using | IsCatchAll = std::is_same< arg_type< _t< std::decay< CatchFn >>>, AnyException > |
template<class T > | |
using | PlacementOf = _t< std::conditional< !IsStdException< T >::value, ThrownTag, _t< std::conditional< sizeof(T)<=sizeof(Buffer::Storage)&&alignof(T)<=alignof(Buffer::Storage)&&noexcept(T(std::declval< T && >()))&&noexcept(T(std::declval< T const & >())), InSituTag, OnHeapTag >>>> |
Private Member Functions | |
template<class Ex , typename... As> | |
exception_wrapper (ThrownTag, in_place_type_t< Ex >, As &&...as) | |
template<class Ex , typename... As> | |
exception_wrapper (OnHeapTag, in_place_type_t< Ex >, As &&...as) | |
template<class Ex , typename... As> | |
exception_wrapper (InSituTag, in_place_type_t< Ex >, As &&...as) | |
Static Private Member Functions | |
static void | onNoExceptionError (char const *name) |
template<class Ret , class... Args> | |
static Ret | noop_ (Args...) |
static std::type_info const * | uninit_type_ (exception_wrapper const *) |
static std::exception const * | as_exception_or_null_ (std::exception const &ex) |
static std::exception const * | as_exception_or_null_ (AnyException) |
template<class This , class... CatchFns> | |
static void | handle_ (std::false_type, This &this_, CatchFns &...fns) |
template<class This , class... CatchFns> | |
static void | handle_ (std::true_type, This &this_, CatchFns &...fns) |
template<class Ex , class This , class Fn > | |
static bool | with_exception_ (This &this_, Fn fn_) |
Private Attributes | |
union { | |
Buffer buff_ {} | |
ExceptionPtr eptr_ | |
SharedPtr sptr_ | |
}; | |
VTable const * | vptr_ {&uninit_} |
Static Private Attributes | |
static VTable const | uninit_ |
Throwing exceptions can be a convenient way to handle errors. Storing exceptions in an exception_ptr
makes it easy to handle exceptions in a different thread or at a later time. exception_ptr
can also be used in a very generic result/exception wrapper.
However, there are some issues with throwing exceptions and std::exception_ptr
. These issues revolve around throw
being expensive, particularly in a multithreaded environment (see ExceptionWrapperBenchmark.cpp).
Imagine we have a library that has an API which returns a result/exception wrapper. Let's consider some approaches for implementing this wrapper. First, we could store a std::exception
. This approach loses the derived exception type, which can make exception handling more difficult for users that prefer rethrowing the exception. We could use a folly::dynamic
for every possible type of exception. This is not very flexible - adding new types of exceptions requires a change to the result/exception wrapper. We could use an exception_ptr
. However, constructing an exception_ptr
as well as accessing the error requires a call to throw. That means that there will be two calls to throw in order to process the exception. For performance sensitive applications, this may be unacceptable.
exception_wrapper
is designed to handle exception management for both convenience and high performance use cases. make_exception_wrapper
is templated on derived type, allowing us to rethrow the exception properly for users that prefer convenience. These explicitly named exception types can therefore be handled without any peformance penalty. exception_wrapper
is also flexible enough to accept any type. If a caught exception is not of an explicitly named type, then std::exception_ptr
is used to preserve the exception state. For performance sensitive applications, the accessor methods can test or extract a pointer to a specific exception type with very little overhead.
Definition at line 162 of file ExceptionWrapper.h.
|
private |
Definition at line 211 of file ExceptionWrapper.h.
|
private |
Definition at line 173 of file ExceptionWrapper.h.
|
private |
Definition at line 214 of file ExceptionWrapper.h.
|
private |
Definition at line 209 of file ExceptionWrapper.h.
|
private |
Definition at line 251 of file ExceptionWrapper.h.
|
inlineprivate |
Definition at line 280 of file ExceptionWrapper-inl.h.
References folly::gen::as(), folly::exception_wrapper::ExceptionPtr::ops_, and vptr_.
|
inlineprivate |
Definition at line 289 of file ExceptionWrapper-inl.h.
References folly::gen::as(), folly::exception_wrapper::SharedPtr::ops_, and vptr_.
|
inlineprivate |
Definition at line 297 of file ExceptionWrapper-inl.h.
References folly::gen::as(), and vptr_.
|
inlinenoexcept |
Default-constructs an empty exception_wrapper
Definition at line 385 of file ExceptionWrapper.h.
References folly::gen::as(), FOLLY_REQUIRES, get_exception(), folly::pushmi::__adl::noexcept(), folly::none, proxygen::operator!(), ptr, folly::swap(), folly::throw_exception(), type, and folly::value().
Referenced by operator=().
|
inlinenoexcept |
Move-constructs an exception_wrapper
*this
contains the value of that
prior to the move that.type() == none()
Definition at line 304 of file ExceptionWrapper-inl.h.
References vptr_.
|
inlinenoexcept |
Copy-constructs an exception_wrapper
*this
contains a copy of that
, and that
is unmodified type() == that.type()
Definition at line 309 of file ExceptionWrapper-inl.h.
References folly::exception_wrapper::VTable::copy_, and vptr_.
|
inline |
Definition at line 331 of file ExceptionWrapper-inl.h.
References reset().
Referenced by folly::Try< void >::emplaceException(), and folly::Try< void >::operator=().
|
explicitnoexcept |
ptr
is empty, or it holds a reference to an exception that is not derived from std::exception
. Definition at line 77 of file ExceptionWrapper.cpp.
References folly::DFATAL, folly::gen::move, and ptr.
|
inlinenoexcept |
ptr
holds a reference to ex
. hasThrownException() == true
bool(*this)
type() == typeid(ex)
Definition at line 336 of file ExceptionWrapper-inl.h.
References folly::exception_wrapper::ExceptionPtr::as_int_(), eptr_, folly::exception_wrapper::ExceptionPtr::ops_, ptr, folly::exception_wrapper::ExceptionPtr::ptr_, and vptr_.
folly::exception_wrapper::exception_wrapper | ( | Ex && | ex | ) |
typeid(ex) == typeid(typename decay<Ex>type)
bool(*this)
hasThrownException() == false
type() == typeid(ex)
std::exception
can be implicitly converted to an exception_wrapper
.
|
inline |
typeid(ex) == typeid(typename decay<Ex>type)
bool(*this)
hasThrownException() == false
type() == typeid(ex)
std::exception
can still be used to construct an exception_wrapper
, but you must specify folly::in_place
as the first parameter. Definition at line 369 of file ExceptionWrapper-inl.h.
References folly::exception_wrapper_detail::dont_slice(), and FOLLY_REQUIRES_DEF.
|
inline |
Definition at line 379 of file ExceptionWrapper-inl.h.
References folly::gen::as().
|
inline |
Definition at line 359 of file ExceptionWrapper-inl.h.
References folly::exception_wrapper_detail::dont_slice(), and FOLLY_REQUIRES_DEF.
|
inlinestaticprivate |
Definition at line 85 of file ExceptionWrapper-inl.h.
Referenced by folly::exception_wrapper::InPlace< Ex >::get_exception_(), and folly::exception_wrapper::SharedPtr::Impl< Ex >::get_exception_().
|
inlinestaticprivate |
Definition at line 89 of file ExceptionWrapper-inl.h.
References folly::kMicrosoftAbiVer.
|
inline |
!*this
, the empty string; otherwise, if type() == unknown()
, the string "\<unknown exception\>"
; otherwise, the result of type().name()
after demangling. Definition at line 454 of file ExceptionWrapper-inl.h.
References folly::demangle(), none(), type(), and unknown().
Referenced by TEST(), and what().
|
staticnoexcept |
Definition at line 63 of file ExceptionWrapper.cpp.
References ptr.
Referenced by TEST(), folly::coro::detail::BlockingWaitPromise< T >::unhandled_exception(), folly::coro::detail::TaskPromise< T >::unhandled_exception(), folly::coro::detail::InlineTaskPromise< T >::unhandled_exception(), folly::coro::detail::BlockingWaitPromise< T & >::unhandled_exception(), folly::coro::detail::TaskPromise< void >::unhandled_exception(), folly::coro::detail::InlineTaskPromise< void >::unhandled_exception(), and folly::coro::detail::BlockingWaitPromise< void >::unhandled_exception().
|
inlinenoexcept |
std::exception
held by *this
, if it holds one; otherwise, returns nullptr
. exception_wrapper
object. Definition at line 406 of file ExceptionWrapper-inl.h.
References folly::exception_wrapper::VTable::get_exception_, and vptr_.
Referenced by fizz::server::detail::processEvent(), and what().
|
inlinenoexcept |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 409 of file ExceptionWrapper-inl.h.
References folly::exception_wrapper::VTable::get_exception_, and vptr_.
|
inlinenoexcept |
Ex
held by *this
, if it holds an object whose type From
permits std::is_convertible<From*, Ex*>
; otherwise, returns nullptr
. exception_wrapper
object. Definition at line 414 of file ExceptionWrapper-inl.h.
References object, and with_exception().
|
inlinenoexcept |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 421 of file ExceptionWrapper-inl.h.
References object, and with_exception().
|
inline |
Handle the wrapped expression as if with a series of catch
clauses, propagating the exception if no handler matches.
std::exception
will be propagated. To specify a catch-all clause, pass a lambda that takes a C-style elipses, as in: !*this
CatchFns... | A pack of unary monomorphic function object types. |
fns | A pack of unary monomorphic function objects to be treated as an ordered list of potential exception handlers. |
throw;
from within your handler – that is, a throw expression with no operand. This may cause your process to terminate. (It is perfectly ok to throw from a handler so long as you specify the exception to throw, as in throw e;
.) Definition at line 659 of file ExceptionWrapper-inl.h.
References handle_(), and onNoExceptionError().
Referenced by fizz::client::AsyncFizzClientT< SM >::deliverHandshakeError(), and TEST().
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 668 of file ExceptionWrapper-inl.h.
References handle_(), and onNoExceptionError().
|
inlinestaticprivate |
Definition at line 586 of file ExceptionWrapper-inl.h.
References folly::exception_wrapper_detail::fold(), handled, and value.
Referenced by handle(), and with_exception_().
|
inlinestaticprivate |
Definition at line 599 of file ExceptionWrapper-inl.h.
References folly::exception_wrapper_detail::fold(), and value.
|
inlinenoexcept |
true
if this exception_wrapper
holds a reference to an exception that was thrown (i.e., if it was constructed with a std::exception_ptr
, or if to_exception_ptr()
was called on a (non-const) reference to *this
). Definition at line 402 of file ExceptionWrapper-inl.h.
References folly::exception_wrapper::ExceptionPtr::ops_, and vptr_.
|
inlinenoexcept |
Ex | The expression type to check for compatibility with. |
true
if and only if *this
wraps an exception that would be caught with a catch(Ex const&)
clause. *this
is empty, this function returns false
. Definition at line 462 of file ExceptionWrapper-inl.h.
References with_exception().
Referenced by TEST().
|
inlinestaticnoexcept |
typeid
of an unspecified type used by exception_wrapper::type()
to denote an empty exception_wrapper
. Definition at line 436 of file ExceptionWrapper-inl.h.
Referenced by class_name(), and TEST().
|
inlinestaticprivate |
Definition at line 62 of file ExceptionWrapper-inl.h.
|
staticprivate |
|
inlineexplicitnoexcept |
true
if *this
is holding an exception. Definition at line 390 of file ExceptionWrapper-inl.h.
References uninit_, and vptr_.
|
inlinenoexcept |
!bool(*this)
Definition at line 394 of file ExceptionWrapper-inl.h.
|
inlinenoexcept |
Move-assigns an exception_wrapper
this != &that
*this
contains the value of that
prior to the move that.type() == none()
Definition at line 318 of file ExceptionWrapper-inl.h.
References folly::exception_wrapper::VTable::delete_, and vptr_.
|
inlinenoexcept |
Copy-assigns an exception_wrapper
*this
contains a copy of that
, and that
is unmodified type() == that.type()
Definition at line 325 of file ExceptionWrapper-inl.h.
References exception_wrapper().
|
inline |
Make this exception_wrapper
empty
!*this
Definition at line 398 of file ExceptionWrapper-inl.h.
References folly::exception_wrapper::VTable::delete_, and vptr_.
Referenced by ~exception_wrapper().
|
inlinenoexcept |
Swaps the value of *this
with the value of that
Definition at line 384 of file ExceptionWrapper-inl.h.
References folly::gen::move.
|
inline |
Throws the wrapped expression.
bool(*this)
Definition at line 466 of file ExceptionWrapper-inl.h.
References onNoExceptionError(), folly::exception_wrapper::VTable::throw_, and vptr_.
Referenced by TEST(), throw_with_nested(), and folly::Try< void >::throwIfFailed().
|
inline |
Throws the wrapped expression nested into another exception.
bool(*this)
ex | Exception in *this will be thrown nested into ex; |
Definition at line 472 of file ExceptionWrapper-inl.h.
References throw_exception().
|
inlinenoexcept |
std::exception_ptr
that references either the exception held by *this
, or a copy of same. *this
to cache the computed std::exception_ptr
; that is, this function may cause has_exception_ptr()
to change from false
to true
. Definition at line 428 of file ExceptionWrapper-inl.h.
References eptr_, folly::exception_wrapper::VTable::get_exception_ptr_, folly::exception_wrapper::ExceptionPtr::ptr_, and vptr_.
Referenced by TEST().
|
inlinenoexcept |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 432 of file ExceptionWrapper-inl.h.
References eptr_, folly::exception_wrapper::VTable::get_exception_ptr_, folly::exception_wrapper::ExceptionPtr::ptr_, and vptr_.
|
inlinenoexcept |
Returns the typeid
of the wrapped exception object. If there is no wrapped exception object, returns exception_wrapper::none()
. If this instance wraps an exception of unknown type not derived from std::exception
, returns exception_wrapper::unknown()
.
Definition at line 443 of file ExceptionWrapper-inl.h.
References folly::exception_wrapper::VTable::type_, and vptr_.
Referenced by class_name().
|
inlinestaticprivate |
Definition at line 66 of file ExceptionWrapper-inl.h.
|
inlinestaticnoexcept |
typeid
of an unspecified type used by exception_wrapper::type()
to denote an exception_wrapper
that holds an exception of unknown type. Definition at line 439 of file ExceptionWrapper-inl.h.
Referenced by class_name().
|
inline |
get_exception() != nullptr
, class_name() + ": " + get_exception()->what()
; otherwise, class_name()
. Definition at line 447 of file ExceptionWrapper-inl.h.
References class_name(), and get_exception().
Referenced by folly::exceptionStr(), fizz::test::HandshakeTest::expectClientSuccess(), fizz::test::HandshakeTest::expectError(), fizz::test::HandshakeTest::expectServerError(), fizz::test::HandshakeTest::expectServerSuccess(), wangle::AcceptRoutingHandler< Pipeline, R >::onError(), fizz::server::AsyncFizzServerT< SM >::ActionMoveVisitor::operator()(), fizz::client::AsyncFizzClientT< SM >::ActionMoveVisitor::operator()(), folly::operator<<(), TEST(), and fizz::client::test::TEST_F().
|
inline |
Call fn
with the wrapped exception (if any), if fn
can accept it.
Ex | Optionally, the type of the exception that fn accepts. |
Fn | The type of a monomophic function object. |
fn | A function object to call with the wrapped exception |
true
if and only if fn
was called. fn
expects, as in throw;
from within your handler – that is, a throw expression with no operand. This may cause your process to terminate. (It is perfectly ok to throw from a handler so long as you specify the exception to throw, as in throw e;
.) Definition at line 650 of file ExceptionWrapper-inl.h.
References folly::gen::move.
Referenced by get_exception(), is_compatible_with(), and TEST().
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 654 of file ExceptionWrapper-inl.h.
References folly::gen::move.
|
inlinestaticprivate |
Definition at line 637 of file ExceptionWrapper-inl.h.
References folly::gen::all(), folly::exception_wrapper_detail::catch_(), handle_(), handled, and folly::gen::move.
union { ... } |
Buffer folly::exception_wrapper::buff_ {} |
Definition at line 339 of file ExceptionWrapper.h.
Referenced by folly::exception_wrapper::Buffer::as(), folly::exception_wrapper::Buffer::Buffer(), folly::exception_wrapper::InPlace< Ex >::copy_(), folly::exception_wrapper::InPlace< Ex >::delete_(), folly::exception_wrapper::InPlace< Ex >::get_exception_(), folly::exception_wrapper::InPlace< Ex >::move_(), and folly::exception_wrapper::InPlace< Ex >::throw_().
ExceptionPtr folly::exception_wrapper::eptr_ |
Definition at line 340 of file ExceptionWrapper.h.
Referenced by folly::exception_wrapper::ExceptionPtr::copy_(), folly::exception_wrapper::ExceptionPtr::delete_(), exception_wrapper(), folly::exception_wrapper::ExceptionPtr::get_exception_(), folly::exception_wrapper::ExceptionPtr::move_(), folly::exception_wrapper::ExceptionPtr::throw_(), to_exception_ptr(), and folly::exception_wrapper::ExceptionPtr::type_().
SharedPtr folly::exception_wrapper::sptr_ |
Definition at line 341 of file ExceptionWrapper.h.
Referenced by folly::exception_wrapper::SharedPtr::copy_(), folly::exception_wrapper::SharedPtr::delete_(), folly::exception_wrapper::SharedPtr::get_exception_(), folly::exception_wrapper::SharedPtr::get_exception_ptr_(), folly::exception_wrapper::SharedPtr::move_(), folly::exception_wrapper::SharedPtr::throw_(), and folly::exception_wrapper::SharedPtr::type_().
|
staticprivate |
Definition at line 206 of file ExceptionWrapper.h.
Referenced by folly::exception_wrapper::ExceptionPtr::delete_(), folly::exception_wrapper::InPlace< Ex >::delete_(), folly::exception_wrapper::SharedPtr::delete_(), and operator bool().
Definition at line 343 of file ExceptionWrapper.h.
Referenced by folly::exception_wrapper::ExceptionPtr::delete_(), folly::exception_wrapper::InPlace< Ex >::delete_(), folly::exception_wrapper::SharedPtr::delete_(), exception_wrapper(), get_exception(), has_exception_ptr(), operator bool(), operator=(), reset(), throw_exception(), to_exception_ptr(), and type().