CoriEngine
Loading...
Searching...
No Matches
Cori::Core::CoriError< DeclaredTypes > Class Template Referencefinal

Custom error class mainly used in std::expected. More...

#include <Error.hpp>

Inheritance diagram for Cori::Core::CoriError< DeclaredTypes >:
Collaboration diagram for Cori::Core::CoriError< DeclaredTypes >:

Public Member Functions

template<typename... Args>
 CoriError (const std::string &message, Args &&... args)
 Constructs CoriError object and formats the final error message.
 ~CoriError () override
 CoriError (const CoriError &other) noexcept
 CoriError (CoriError &&other) noexcept
CoriErroroperator= (const CoriError &other)=delete
CoriErroroperator= (CoriError &&other) noexcept=delete
const char * what () const noexcept override
 Returns the formated message and if called the CoriError is considered 'seen'.
void Ignore () const
 Explicitly sets the CoriError object into 'seen' state.
template<typename T>
Get () const
 Retrieves the value of the type requested from the CoriError object.
template<typename... Types>
requires (sizeof...(Types) > 1)
std::tuple< Types... > Get () const
 The overload of Get method for use with structured bindings.

Detailed Description

template<typename... DeclaredTypes>
class Cori::Core::CoriError< DeclaredTypes >

Custom error class mainly used in std::expected.

Template Parameters
DeclaredTypesTypes that will be obtainable.

Can hold variables that are passed upon creation that are later obtainable via Get method, duplicate types are illegal. As it is derived from std::exception it can be thrown.
If a CoriError object was constructed and never 'seen' it will print the formated error message upon destruction.
DeclaredTypes typenames will be embedded into the formated error message alongside the user-defined description for each one, and if they are streamable their value will be embedded as well.
Example usage:
Example specialization: CoriError<int, std::type_index>
Constructed like this: CoriError<int, std::type_index>("Main error message", "user-defined description for int", intValue, "user-defined description for std::type_index", type_indexValue);
The final error message will be: Main error message | Additional data: (user-defined description for int (int): 'intValue', user-defined description for std::type_index (std::type_index): 'Type is not streamable, you can retrieve it with Get<T>()') |
Also all the types from DeclaredTypes can be later retried using Get<T>(), and it also supports retrieving multiple at a time and returning them in a tuple.

Definition at line 27 of file Error.hpp.

Constructor & Destructor Documentation

◆ CoriError() [1/3]

template<typename... DeclaredTypes>
template<typename... Args>
Cori::Core::CoriError< DeclaredTypes >::CoriError ( const std::string & message,
Args &&... args )
inlineexplicit

Constructs CoriError object and formats the final error message.

Template Parameters
ArgsDeduced automatically, no need to specify.
Parameters
messageMain error message.
argsPairs descriptions and values for each DeclaredTypes.

Definition at line 36 of file Error.hpp.

◆ ~CoriError()

template<typename... DeclaredTypes>
Cori::Core::CoriError< DeclaredTypes >::~CoriError ( )
inlineoverride

Definition at line 53 of file Error.hpp.

Here is the call graph for this function:

◆ CoriError() [2/3]

template<typename... DeclaredTypes>
Cori::Core::CoriError< DeclaredTypes >::CoriError ( const CoriError< DeclaredTypes > & other)
inlinenoexcept

Definition at line 59 of file Error.hpp.

Here is the call graph for this function:

◆ CoriError() [3/3]

template<typename... DeclaredTypes>
Cori::Core::CoriError< DeclaredTypes >::CoriError ( CoriError< DeclaredTypes > && other)
inlinenoexcept

Definition at line 63 of file Error.hpp.

Here is the call graph for this function:

Member Function Documentation

◆ Get() [1/2]

template<typename... DeclaredTypes>
template<typename T>
T Cori::Core::CoriError< DeclaredTypes >::Get ( ) const
inline

Retrieves the value of the type requested from the CoriError object.

Template Parameters
TType to retrieve.
Returns
Value associated with the type provided.

Definition at line 94 of file Error.hpp.

◆ Get() [2/2]

template<typename... DeclaredTypes>
template<typename... Types>
requires (sizeof...(Types) > 1)
std::tuple< Types... > Cori::Core::CoriError< DeclaredTypes >::Get ( ) const
inline

The overload of Get method for use with structured bindings.

Template Parameters
TypesA pack of types to retrieve.
Returns
A tuple containing the values requested.

Definition at line 111 of file Error.hpp.

Here is the call graph for this function:

◆ Ignore()

template<typename... DeclaredTypes>
void Cori::Core::CoriError< DeclaredTypes >::Ignore ( ) const
inline

Explicitly sets the CoriError object into 'seen' state.

Definition at line 84 of file Error.hpp.

◆ operator=() [1/2]

template<typename... DeclaredTypes>
CoriError & Cori::Core::CoriError< DeclaredTypes >::operator= ( const CoriError< DeclaredTypes > & other)
delete
Here is the call graph for this function:

◆ operator=() [2/2]

template<typename... DeclaredTypes>
CoriError & Cori::Core::CoriError< DeclaredTypes >::operator= ( CoriError< DeclaredTypes > && other)
deletenoexcept
Here is the call graph for this function:

◆ what()

template<typename... DeclaredTypes>
const char * Cori::Core::CoriError< DeclaredTypes >::what ( ) const
inlineoverridenoexcept

Returns the formated message and if called the CoriError is considered 'seen'.

Returns
Formated error message.

Definition at line 74 of file Error.hpp.


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