A11 (C++ runtime)
Native C++ implementation of the A11 streaming action runtime
Loading...
Searching...
No Matches
a11::exception_guard Namespace Reference

Namespaces

namespace  internal
 

Functions

template absl::AnyInvocable< void() && > WrapConsuming< void > (absl::AnyInvocable< void() && >, std::string_view)
 For a11::Schedule and a11::ScheduleCancelable: work run once and discarded.
 
template<typename Callable >
absl::Status Attempt (Callable &&callable, std::string_view what)
 Runs callable, reporting anything it throws as a Status.
 
template<typename Result , typename... Args>
std::function< Result(Args...)> Wrap (std::function< Result(Args...)> callable, std::string_view what)
 Wraps callable so that anything it throws becomes a failure.
 
template<typename Result , typename... Args>
absl::AnyInvocable< Result(Args...)> WrapOnce (absl::AnyInvocable< Result(Args...)> callable, std::string_view what)
 Wrap for a move-only callable.
 
template<typename Result , typename... Args>
absl::AnyInvocable< Result(Args...) && > WrapConsuming (absl::AnyInvocable< Result(Args...) && > callable, std::string_view what)
 Wrap for a callable that is consumed by its one invocation.
 

Function Documentation

◆ Attempt()

template<typename Callable >
absl::Status a11::exception_guard::Attempt ( Callable &&  callable,
std::string_view  what 
)

Runs callable, reporting anything it throws as a Status.

For a template in a header, where the instantiating translation unit is both the one that supplies the callable and the one that decides whether exceptions exist. See the file comment: inside A11 this is a plain call, and it is not the tool for a callable stored by A11 and invoked later.

Parameters
callableAnything invocable with no arguments and no return value.
whatHow to name it in the error, e.g. "on_message".
Returns
OK, or what the callable threw.

◆ Wrap()

template<typename Result , typename... Args>
std::function< Result(Args...)> a11::exception_guard::Wrap ( std::function< Result(Args...)>  callable,
std::string_view  what 
)

Wraps callable so that anything it throws becomes a failure.

What "a failure" means depends on the return type: an error absl::Status or absl::StatusOr, a failed a11::Future, and for a callable returning void a logged error and nothing else – which is all a caller of a void callback could have done with it anyway.

Parameters
callableWhat the caller handed us. An empty callable is returned as is, so a caller's own emptiness check still sees what it expects.
whatHow to name the callable in the error, e.g. "on_message". The message reads <what> raised: <e.what()>, or <what> raised a non-standard exception for something that is not a std::exception.

◆ WrapConsuming()

template<typename Result , typename... Args>
absl::AnyInvocable< Result(Args...) && > a11::exception_guard::WrapConsuming ( absl::AnyInvocable< Result(Args...) && >  callable,
std::string_view  what 
)

Wrap for a callable that is consumed by its one invocation.

◆ WrapConsuming< void >()

template absl::AnyInvocable< void() && > a11::exception_guard::WrapConsuming< void > ( absl::AnyInvocable< void() && >  ,
std::string_view   
)

For a11::Schedule and a11::ScheduleCancelable: work run once and discarded.

◆ WrapOnce()

template<typename Result , typename... Args>
absl::AnyInvocable< Result(Args...)> a11::exception_guard::WrapOnce ( absl::AnyInvocable< Result(Args...)>  callable,
std::string_view  what 
)

Wrap for a move-only callable.