folly::result_catch_all

Wraps the return value from the lambda fn in a result, putting any thrown exception into its "error" state.

Synopsis

Declared in <folly/result/result.h>

template<
    typename F,
    typename RetF = decltype(FOLLY_DECLVAL(F&&)())>
conditional_t<is_instantiation_of_v<result, RetF>, RetF, result<RetF>>
result_catch_all(F&& fn) noexcept;

Description

return result_catch_all(&{ return riskyWork(); });

Note:

  • result<> coroutines catch unhandled exceptions, but can additionally throw bad_alloc for coro frame allocations (but see LLVM PR 152623).

  • Like all functions, result<> non-coroutines let exceptions fly.

Return Value

A result holding fn's return value, or its thrown exception.

Parameters

NameDescription
fnThe callable to invoke and wrap.