![]() |
cpp_error_utils 1.0.0
C++ error handling utilities
|
Error handling utilities for C++ applications. More...
Go to the source code of this file.
Classes | |
class | error_utils::Error |
A wrapper class for system error codes with additional context. More... | |
Namespaces | |
namespace | error_utils |
Contains utilities for error handling and classification. | |
Macros | |
#define | CPP_ERROR_UTILS_VERSION_MAJOR 1 |
cpp_error_utils major version number | |
#define | CPP_ERROR_UTILS_VERSION_MINOR 0 |
Minor version number. | |
#define | CPP_ERROR_UTILS_VERSION_PATCH 0 |
Library patch number. | |
Typedefs | |
template<typename T = void> | |
using | error_utils::Result = std::expected<T, Error> |
A specialization of std::expected for the Error type. | |
using | error_utils::VoidResult = Result<> |
Result type for void (std::expected<void, Error>) | |
using | error_utils::StringResult = Result<std::string> |
Result type for strings (std::expected<std::string, Error>) | |
using | error_utils::IntResult = Result<int> |
Result type for integers (std::expected<int, Error>) | |
using | error_utils::BoolResult = Result<bool> |
Result type for booleans (std::expected<bool, Error>) | |
template<typename T = void> | |
using | Result |
A specialization of std::expected for the Error type. | |
using | VoidResult |
Result type for void (std::expected<void, Error>) | |
using | StringResult |
Result type for strings (std::expected<std::string, Error>) | |
using | IntResult |
Result type for integers (std::expected<int, Error>) | |
using | BoolResult |
Result type for booleans (std::expected<bool, Error>) | |
Functions | |
constexpr std::error_code | error_utils::make_error_code (ExtraError e) |
Create an error code from an ExtraError enum value. | |
constexpr std::error_condition | error_utils::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 > | error_utils::make_error (E &&code, Ctx &&context={}) |
Create an error result of the specified type. | |
template<typename T> | |
constexpr Result< T > | error_utils::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 > | error_utils::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 | error_utils::last_error () noexcept |
Retrieve the last system error code and reset errno . | |
template<typename T> | |
Result< T > | error_utils::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 | error_utils::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 | error_utils::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 | error_utils::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 > | error_utils::first_of (std::initializer_list< Result< T > > results) |
Return first success result from multiple alternatives. | |
Error handling utilities for C++ applications.
This module provides various utilities for error handling, including error codes and conditions that can be used throughout C++ applications.
#define CPP_ERROR_UTILS_VERSION_MAJOR 1 |
cpp_error_utils
major version number
#define CPP_ERROR_UTILS_VERSION_MINOR 0 |
Minor version number.
#define CPP_ERROR_UTILS_VERSION_PATCH 0 |
Library patch number.
using error_utils::BoolResult |
Result type for booleans (std::expected<bool, Error>)
using error_utils::IntResult |
Result type for integers (std::expected<int, Error>)
using error_utils::Result |
A specialization of std::expected
for the Error
type.
T | The type of the expected value. Defaults to void |
Result type for strings (std::expected<std::string, Error>)
using error_utils::VoidResult |
Result type for void (std::expected<void, Error>)
|
strong |
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
|
strong |
Represents categories of error conditions for error handling and classification.
This enumeration defines broad categories of errors that can occur in the system, which are used to group specific error codes into more general error conditions.