libcaf  0.15.3
Public Types | 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>

Inherits comparable< error >.

Public Types

using inspect_fun = std::function< error(meta::type_name_t, uint8_t &, atom_value &, meta::omittable_if_empty_t, message &)>
 

Public Member Functions

 error (none_t) noexcept
 
 error (error &&) noexcept
 
erroroperator= (error &&) noexcept
 
 error (const error &)
 
erroroperator= (const error &)
 
 error (uint8_t x, atom_value y)
 
 error (uint8_t x, atom_value y, message z)
 
template<class E , class = enable_if_has_make_error_t<E>>
 error (E error_value)
 
template<class E , class = enable_if_has_make_error_t<E>>
erroroperator= (E error_value)
 
uint8_t code () const noexcept
 Returns the category-specific error code, whereas 0 means "no error". More...
 
atom_value category () const noexcept
 Returns the category of 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.
 
int compare (const error &) const noexcept
 
int compare (uint8_t x, atom_value y) const noexcept
 
messagecontext () noexcept
 Returns context information to this error. More...
 
void clear () noexcept
 Sets the error code to 0.
 

Friends

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

Related Functions

(Note that these are not member functions.)

std::string to_string (const error &x)
 
bool operator== (const error &x, none_t)
 
bool operator== (none_t, const error &x)
 
template<class E , class = enable_if_has_make_error_t<E>>
bool operator== (const error &x, E y)
 
template<class E , class = enable_if_has_make_error_t<E>>
bool operator== (E x, const error &y)
 
bool operator!= (const error &x, none_t)
 
bool operator!= (none_t, const error &x)
 
template<class E , class = enable_if_has_make_error_t<E>>
bool operator!= (const error &x, E y)
 
template<class E , class = enable_if_has_make_error_t<E>>
bool operator!= (E 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 atoms for categories instead and requires users to register custom error categories to the actor system. This makes the actor system the natural instance for rendering error messages via actor_system::render(const error&).

Member Function Documentation

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

Returns the category of this error.

Precondition
*this != none
uint8_t caf::error::code ( ) const
noexcept

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

Precondition
*this != none
const message& caf::error::context ( ) const
noexcept

Returns context information to this error.

Precondition
*this != none
message& caf::error::context ( )
noexcept

Returns context information to this error.

Precondition
*this != none

Friends And Related Function Documentation

bool operator!= ( const error x,
none_t   
)
related
bool operator!= ( none_t  ,
const error x 
)
related
template<class E , class = enable_if_has_make_error_t<E>>
bool operator!= ( const error x,
y 
)
related
template<class E , class = enable_if_has_make_error_t<E>>
bool operator!= ( x,
const error y 
)
related
bool operator== ( const error x,
none_t   
)
related
bool operator== ( none_t  ,
const error x 
)
related
template<class E , class = enable_if_has_make_error_t<E>>
bool operator== ( const error x,
y 
)
related
template<class E , class = enable_if_has_make_error_t<E>>
bool operator== ( x,
const error y 
)
related
std::string to_string ( const error x)
related

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