cpp_error_utils 1.0.0
C++ error handling utilities
Loading...
Searching...
No Matches
error_utils::Error Class Reference

A wrapper class for system error codes with additional context. More...

#include <error_utils.hpp>

Public Member Functions

constexpr Error () noexcept=default
 
constexpr Error (const std::error_code &code, const std::string_view context={})
 Create an error with the specified error code and optional context.
 
constexpr Error (const detail::convertible_to_error_code auto code, const std::string_view context={})
 Create an error with a type convertible to std::error_code and optional context.
 
constexpr Error (const Error &other) noexcept=default
 
constexpr Error (Error &&other) noexcept
 
constexpr Erroroperator= (const Error &other)
 
constexpr Erroroperator= (Error &&other) noexcept
 
 ~Error () noexcept=default
 
constexpr operator bool () const noexcept
 Implicit conversion to bool, indicating whether an error exists.
 
constexpr const std::error_code & error_code () const noexcept
 Returns a constant reference to the underlying error code.
 
constexpr const std::string & context () const noexcept
 Returns a constant reference to the context string.
 
constexpr int value () const noexcept
 Returns the value of the error code.
 
constexpr const std::error_category & category () const noexcept
 Returns the category of the error code.
 
constexpr std::string message () const
 Get the error message including context if available.
 
template<typename T>
requires detail::comparable_to_error_code<T>
constexpr bool is (T &&code) const noexcept
 Check if the error is of a specific type.
 
template<typename Code, typename... Others>
requires detail::comparable_to_error_code<Code> && (detail::comparable_to_error_code<Others> && ...)
constexpr bool is_any_of (Code &&code, Others &&... others) const noexcept
 Check if the error belongs to any of the specified error codes or error conditions.
 

Friends

constexpr friend bool operator== (const Error &lhs, const Error &rhs) noexcept
 
constexpr friend auto operator<=> (const Error &lhs, const Error &rhs) noexcept
 
constexpr friend bool operator== (const Error &lhs, const std::error_code &rhs) noexcept
 
constexpr friend auto operator<=> (const Error &lhs, const std::error_code &rhs) noexcept
 
constexpr friend bool operator== (const Error &lhs, const std::error_condition &rhs) noexcept
 
constexpr friend std::ostream & operator<< (std::ostream &os, const Error &obj)
 
constexpr friend void swap (Error &lhs, Error &rhs) noexcept
 Swap the contents of two Error objects.
 

Detailed Description

A wrapper class for system error codes with additional context.

Constructor & Destructor Documentation

◆ Error() [1/5]

error_utils::Error::Error ( )
constexprdefaultnoexcept

◆ Error() [2/5]

error_utils::Error::Error ( const std::error_code & code,
const std::string_view context = {} )
inlineexplicitconstexpr

Create an error with the specified error code and optional context.

Parameters
codeThe system error code
contextAdditional context information about the error

◆ Error() [3/5]

error_utils::Error::Error ( const detail::convertible_to_error_code auto code,
const std::string_view context = {} )
inlineexplicitconstexpr

Create an error with a type convertible to std::error_code and optional context.

Parameters
codeThe error code
contextAdditional context information about the error

◆ Error() [4/5]

error_utils::Error::Error ( const Error & other)
constexprdefaultnoexcept

◆ Error() [5/5]

error_utils::Error::Error ( Error && other)
inlineconstexprnoexcept

◆ ~Error()

error_utils::Error::~Error ( )
defaultnoexcept

Member Function Documentation

◆ category()

const std::error_category & error_utils::Error::category ( ) const
inlinenodiscardconstexprnoexcept

Returns the category of the error code.

◆ context()

const std::string & error_utils::Error::context ( ) const
inlinenodiscardconstexprnoexcept

Returns a constant reference to the context string.

◆ error_code()

const std::error_code & error_utils::Error::error_code ( ) const
inlinenodiscardconstexprnoexcept

Returns a constant reference to the underlying error code.

◆ is()

template<typename T>
requires detail::comparable_to_error_code<T>
bool error_utils::Error::is ( T && code) const
inlinenodiscardconstexprnoexcept

Check if the error is of a specific type.

Parameters
codeThe error code to check against
Template Parameters
TThe type of the error code
Returns
True if the error matches the specified code.

◆ is_any_of()

template<typename Code, typename... Others>
requires detail::comparable_to_error_code<Code> && (detail::comparable_to_error_code<Others> && ...)
bool error_utils::Error::is_any_of ( Code && code,
Others &&... others ) const
inlinenodiscardconstexprnoexcept

Check if the error belongs to any of the specified error codes or error conditions.

Parameters
codeThe first error code/condition to check against
othersOther error codes/conditions to check against
Template Parameters
CodeThe type of the first argument
OthersThe types of the other arguments
Returns
True if the error matches any of the arguments.

◆ message()

std::string error_utils::Error::message ( ) const
inlinenodiscardconstexpr

Get the error message including context if available.

Returns
Formatted error message

◆ operator bool()

error_utils::Error::operator bool ( ) const
inlineexplicitnodiscardconstexprnoexcept

Implicit conversion to bool, indicating whether an error exists.

◆ operator=() [1/2]

Error & error_utils::Error::operator= ( const Error & other)
inlineconstexpr

◆ operator=() [2/2]

Error & error_utils::Error::operator= ( Error && other)
inlineconstexprnoexcept

◆ value()

int error_utils::Error::value ( ) const
inlinenodiscardconstexprnoexcept

Returns the value of the error code.

Friends And Related Symbol Documentation

◆ operator<<

friend std::ostream & operator<< ( std::ostream & os,
const Error & obj )
friend

◆ operator<=> [1/2]

friend auto operator<=> ( const Error & lhs,
const Error & rhs )
friend

◆ operator<=> [2/2]

friend auto operator<=> ( const Error & lhs,
const std::error_code & rhs )
friend

◆ operator== [1/3]

friend bool operator== ( const Error & lhs,
const Error & rhs )
friend

◆ operator== [2/3]

friend bool operator== ( const Error & lhs,
const std::error_code & rhs )
friend

◆ operator== [3/3]

friend bool operator== ( const Error & lhs,
const std::error_condition & rhs )
friend

◆ swap

friend void swap ( Error & lhs,
Error & rhs )
friend

Swap the contents of two Error objects.


The documentation for this class was generated from the following file: