78#ifndef A11_EXCEPTION_GUARD_H_
79#define A11_EXCEPTION_GUARD_H_
86#include <absl/functional/any_invocable.h>
87#include <absl/status/status.h>
95absl::Status
Raised(
const std::exception&
error, std::string_view what);
113template <
typename Callable>
114absl::Status
Attempt([[maybe_unused]] Callable&& callable,
115 [[maybe_unused]] std::string_view what) {
116#if defined(__cpp_exceptions) || defined(__EXCEPTIONS)
118 std::forward<Callable>(callable)();
119 }
catch (
const std::exception&
error) {
124 return absl::OkStatus();
126 std::forward<Callable>(callable)();
127 return absl::OkStatus();
145template <
typename Result,
typename... Args>
146std::function<Result(Args...)>
Wrap(std::function<Result(Args...)> callable,
147 std::string_view what);
150template <
typename Result,
typename... Args>
152 absl::AnyInvocable<Result(Args...)> callable, std::string_view what);
155template <
typename Result,
typename... Args>
157 absl::AnyInvocable<Result(Args...) &&> callable, std::string_view what);
absl::Status RaisedUnknown(std::string_view what)
The same, for something thrown that is not a std::exception.
Definition exception_guard.cc:36
absl::Status Raised(const std::exception &error, std::string_view what)
Definition exception_guard.cc:32
Definition boundary.cc:37
absl::Status Attempt(Callable &&callable, std::string_view what)
Runs callable, reporting anything it throws as a Status.
Definition exception_guard.h:114
std::function< Result(Args...)> Wrap(std::function< Result(Args...)> callable, std::string_view what)
Wraps callable so that anything it throws becomes a failure.
absl::AnyInvocable< Result(Args...)> WrapOnce(absl::AnyInvocable< Result(Args...)> callable, std::string_view what)
Wrap for a move-only callable.
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.
absl::Status error
Definition runtime.cc:643