|
constexpr std::error_code | make_error_code (ExtraError e) |
| Create an error code from an ExtraError enum value.
|
|
constexpr std::error_condition | make_error_condition (ExtraErrorCondition e) |
| Create an error condition from an ExtraErrorCondition enum value.
|
|
template<typename T, typename E, typename Ctx = std::string_view>
requires detail::convertible_to_error_code<E> |
constexpr Result< T > | make_error (E &&code, Ctx &&context={}) |
| Create an error result of the specified type.
|
|
template<typename T> |
constexpr Result< T > | make_error (const std::error_code &code, const std::string_view context={}) |
| Create an error result of the specified type from a std::error_code .
|
|
template<typename T> |
constexpr Result< T > | make_error (const std::regex_constants::error_type code, std::string_view context={}) |
| Create an error result of the specified type from a std::regex_constants::error_type .
|
|
std::error_code | last_error () noexcept |
| Retrieve the last system error code and reset errno .
|
|
template<typename T> |
Result< T > | make_error_from_errno (const std::string_view context={}) |
| Create an error result from the current errno value.
|
|
template<typename Func, typename R = std::invoke_result_t<Func>> |
auto | with_errno (Func &&func, const std::string_view error_context={}) -> Result< R > |
| Execute a function that may set errno, capturing the result and any error.
|
|
template<typename Func>
requires std::is_nothrow_invocable_v<Func> |
IntResult | invoke_with_syscall_api (Func &&func, const std::string_view error_context={}) noexcept |
| Execute a function that may set errno , capturing the result and any error.
|
|
template<typename Func, typename R = std::invoke_result_t<Func>> |
constexpr auto | try_catch (Func &&func, std::string_view context={}) -> Result< R > |
| Execute a function and catch common exceptions, converting them to errors.
|
|
template<typename T> |
constexpr Result< T > | first_of (std::initializer_list< Result< T > > results) |
| Return first success result from multiple alternatives.
|
|
Contains utilities for error handling and classification.
Represents specific error codes for exception handling and error classification.
This scoped enumeration defines detailed error codes that map to specific C++ standard library exceptions, providing a unified way to handle various error types.
It is designed to work with the standard error handling facilities and integrates with std::error_code
and std::error_condition
Enumerator |
---|
invalid_argument | std::invalid_argument exception.
|
length_error | std::length_error exception.
|
logic_error | std::logic_error base exception.
|
value_too_small | std::underflow_error exception.
|
nonexistent_local_time | std::chrono::nonexistent_local_time exception.
|
ambiguous_local_time | std::chrono::ambiguous_local_time exception.
|
format_error | std::format_error exception.
|
runtime_error | std::runtime_error base exception.
|
bad_alloc | std::bad_alloc exception.
|
bad_typeid | std::bad_typeid exception.
|
bad_cast | std::bad_cast exception.
|
bad_optional_access | std::bad_optional_access exception.
|
bad_expected_access | std::bad_expected_access exception.
|
bad_variant_access | std::bad_variant_access exception.
|
bad_weak_ptr | std::bad_weak_ptr exception.
|
bad_function_call | std::bad_function_call exception.
|
bad_exception | std::bad_exception exception.
|
exception | all std::exception exceptions.
|
unknown_exception | catch-all for any other exceptions.
|
unknown_error | Unknown error (not related to exceptions).
|
template<typename Func>
requires std::is_nothrow_invocable_v<Func>
IntResult error_utils::invoke_with_syscall_api |
( |
Func && | func, |
|
|
const std::string_view | error_context = {} ) |
|
nodiscardnoexcept |
Execute a function that may set errno
, capturing the result and any error.
This function is intended for use with system calls that return an integer result, where a return value of -1 indicates an error.
- Parameters
-
func | Function that may set errno. Expected to return an integral type convertible to int. |
- Template Parameters
-
Func | Type of the function to execute |
- Parameters
-
error_context | Context to use if an error occurs |
- Template Parameters
-
Func | The type of the function to execute |
- Returns
- Result of the function or an error if errno was set
- Note
- The
errno
value is reset before and after the function call.
-
The function must be
noexcept
to ensure that it does not throw exceptions.
-
Notice that the function must be invocable with no arguments.
-
Use a lambda or
std::bind
to wrap the function.