C++ Actor Framework  0.18
Public Member Functions | Friends | Related Functions | List of all members
caf::error Class Reference

A serializable type for storing error codes with category and optional, human-readable context information. More...

#include <error.hpp>

Inheritance diagram for caf::error:
Inheritance graph
Collaboration diagram for caf::error:
Collaboration graph

Public Member Functions

 error (none_t) noexcept
 
 error (error &&) noexcept=default
 
erroroperator= (error &&) noexcept=default
 
 error (const error &)
 
erroroperator= (const error &)
 
template<class Enum , class = std::enable_if_t<is_error_code_enum_v<Enum>>>
 error (Enum code)
 
template<class Enum , class = std::enable_if_t<is_error_code_enum_v<Enum>>>
 error (Enum code, message context)
 
template<class Enum >
 error (error_code< Enum > code)
 
template<class E >
erroroperator= (E error_value)
 
template<class E >
erroroperator= (error_code< E > code)
 
uint8_t code () const noexcept
 Returns the category-specific error code, whereas 0 means "no error". More...
 
type_id_t category () const noexcept
 Returns the ::type_id of the category for this error. More...
 
const messagecontext () const noexcept
 Returns context information to this error. More...
 
 operator bool () const noexcept
 Returns *this != none.
 
bool operator! () const noexcept
 Returns *this == none.
 
bool empty () const noexcept
 Returns whether this error was default-constructed.
 
int compare (const error &) const noexcept
 
int compare (uint8_t code, type_id_t category) const noexcept
 

Friends

template<class Inspector >
bool inspect (Inspector &f, error &x)
 

Related Functions

(Note that these are not member functions.)

CAF_CORE_EXPORT std::string to_string (const error &x)
 
template<class Enum >
std::enable_if_t< is_error_code_enum_v< Enum >, errormake_error (Enum code)
 
template<class Enum , class T , class... Ts>
std::enable_if_t< is_error_code_enum_v< Enum >, errormake_error (Enum code, T &&x, Ts &&... xs)
 
bool operator== (const error &x, none_t)
 
bool operator== (none_t, const error &x)
 
template<class Enum >
std::enable_if_t< is_error_code_enum_v< Enum >, bool > operator== (const error &x, Enum y)
 
template<class Enum >
std::enable_if_t< is_error_code_enum_v< Enum >, bool > operator== (Enum x, const error &y)
 
bool operator!= (const error &x, none_t)
 
bool operator!= (none_t, const error &x)
 
template<class Enum >
std::enable_if_t< is_error_code_enum_v< Enum >, bool > operator!= (const error &x, Enum y)
 
template<class Enum >
std::enable_if_t< is_error_code_enum_v< Enum >, bool > operator!= (Enum x, const error &y)
 

Detailed Description

A serializable type for storing error codes with category and optional, human-readable context information.

Unlike error handling classes from the C++ standard library, this type is serializable. It consists of an 8-bit code, a 64-bit atom constant, plus optionally a ::message to store additional information.

Why not std::error_code or std::error_condition?

First, the standard does not define the values for std::errc. This means serializing error conditions (which are meant to be portable) is not safe in a distributed setting unless all machines are running the same operating system and version of the C++ standard library.

Second, the standard library primitives, unlike exceptions, do not offer an API for attaching additional context to an error. The error handling API offered by the standard is meant to wrap C system calls in a (source code) portable way. In a distributed setting, an error may not occur locally. In this case, an error code and category alone is often not satisfactory information when signalling errors back to end users. The additional context also enables composition of errors by modifying the message details as needed.

Why is there no string() member function?

The C++ standard library uses category singletons and virtual dispatching to correlate error codes to descriptive strings. However, singletons are a poor choice when it comes to serialization. CAF uses type IDs and meta objects instead.

Member Function Documentation

◆ category()

type_id_t caf::error::category ( ) const
noexcept

Returns the ::type_id of the category for this error.

Precondition
*this != none

◆ code()

uint8_t caf::error::code ( ) const
noexcept

Returns the category-specific error code, whereas 0 means "no error".

Precondition
*this != none

◆ context()

const message& caf::error::context ( ) const
noexcept

Returns context information to this error.

Precondition
*this != none

Friends And Related Function Documentation

◆ make_error() [1/2]

template<class Enum >
std::enable_if_t< is_error_code_enum_v< Enum >, error > make_error ( Enum  code)
related

◆ make_error() [2/2]

template<class Enum , class T , class... Ts>
std::enable_if_t< is_error_code_enum_v< Enum >, error > make_error ( Enum  code,
T &&  x,
Ts &&...  xs 
)
related

◆ operator!=() [1/4]

bool operator!= ( const error x,
none_t   
)
related

◆ operator!=() [2/4]

bool operator!= ( none_t  ,
const error x 
)
related

◆ operator!=() [3/4]

template<class Enum >
std::enable_if_t< is_error_code_enum_v< Enum >, bool > operator!= ( const error x,
Enum  y 
)
related

◆ operator!=() [4/4]

template<class Enum >
std::enable_if_t< is_error_code_enum_v< Enum >, bool > operator!= ( Enum  x,
const error y 
)
related

◆ operator==() [1/4]

bool operator== ( const error x,
none_t   
)
related

◆ operator==() [2/4]

bool operator== ( none_t  ,
const error x 
)
related

◆ operator==() [3/4]

template<class Enum >
std::enable_if_t< is_error_code_enum_v< Enum >, bool > operator== ( const error x,
Enum  y 
)
related

◆ operator==() [4/4]

template<class Enum >
std::enable_if_t< is_error_code_enum_v< Enum >, bool > operator== ( Enum  x,
const error y 
)
related

◆ to_string()

CAF_CORE_EXPORT std::string to_string ( const error x)
related

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