HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions
tt::error_info Class Reference

#include <ttauri/error_info.hpp>

Public Member Functions

 error_info (source_location location) noexcept
 Open an error info transaction.
 
 error_info (bool reopen) noexcept
 Reopen a error info transaction.
 
 error_info (error_info &&rhs) noexcept=delete
 
error_infooperator= (error_info &&rhs) noexcept=delete
 
 error_info (error_info const &rhs)=delete
 
error_infooperator= (error_info const &rhs)=delete
 
template<basic_fixed_string Tag, typename Arg >
error_infoset (Arg &&value) noexcept
 Set an information for a given tag.
 

Static Public Member Functions

static void close () noexcept
 Close the current transaction.
 
template<typename ValueType , basic_fixed_string Tag>
static std::optional< ValueType > pop () noexcept
 Destructive read data from the current transaction.
 
template<typename ValueType , basic_fixed_string Tag>
static std::optional< ValueType > peek () noexcept
 Non-destructive read data from the current transaction.
 
static std::string string () noexcept
 Return the list of entries with their current set value.
 

Detailed Description

Error information passed alongside an error code or exception.

Example:

try {
try {
tt_error_info().set<"errno">(errno);
throw std::runtime_error("foo");
} catch (runtime_error const &e) {
// Add more information during the catch.
tt::error_info(true).set<"url">(file_url);
throw
}
} catch (runtime_error const &e) {
auto error_url = *tt::error_info::pop<URL, "url">();
auto error_errno = *tt::error_info::pop<int, "errno">();
tt_log_error("Config file error in file {}, errno={}", error_url, error_errno);
}
Error information passed alongside an error code or exception.
Definition error_info.hpp:81
static std::optional< ValueType > pop() noexcept
Destructive read data from the current transaction.
Definition error_info.hpp:185
error_info & set(Arg &&value) noexcept
Set an information for a given tag.
Definition error_info.hpp:144

Constructor & Destructor Documentation

◆ error_info() [1/2]

tt::error_info::error_info ( source_location location)
inlinenoexcept

Open an error info transaction.

A transaction may only be opened when the error_info is in idle state; just before throwing an exception.

◆ error_info() [2/2]

tt::error_info::error_info ( bool reopen)
inlinenoexcept

Reopen a error info transaction.

A closed transaction may be reopened to add more information to a thrown exception. Used when (re-)throwing an exception from a catch block.

Parameters
reopenTrue when reopening an error_info transaction. Must be set to true.

Member Function Documentation

◆ close()

static void tt::error_info::close ( )
inlinestaticnoexcept

Close the current transaction.

After the transaction is closed it can no longer be reopened or written to.

This function should be called in a non-throwing catch block, either directly or through the usage of error_info::pop or to_string(std::exception &e, bool)

◆ peek()

template<typename ValueType , basic_fixed_string Tag>
static std::optional< ValueType > tt::error_info::peek ( )
inlinestaticnoexcept

Non-destructive read data from the current transaction.

This function will NOT close the current transaction.

Template Parameters
Taga struct type used as an identifier. This struct type should have a public typedef of value_type for the value returned by this function.
Returns
The value to if it was set, or empty.

◆ pop()

template<typename ValueType , basic_fixed_string Tag>
static std::optional< ValueType > tt::error_info::pop ( )
inlinestaticnoexcept

Destructive read data from the current transaction.

This function will close the current transaction. Continued pop() and peek() calls will still be able to read from the current, but closed, transaction.

Template Parameters
Taga struct type used as an identifier. This struct type should have a public typedef of value_type for the value returned by this function.
Returns
The value to if it was set, or empty.

◆ set()

template<basic_fixed_string Tag, typename Arg >
error_info & tt::error_info::set ( Arg && value)
inlinenoexcept

Set an information for a given tag.

You can chain multiple .set() calls.

Template Parameters
Taga struct type used as an identifier. This struct type should have a public typedef of value_type for the value set in this function.
Parameters
valueThe value to set.
Returns
A reference to the error_info, for chaining of .set() calls.

◆ string()

static std::string tt::error_info::string ( )
inlinestaticnoexcept

Return the list of entries with their current set value.


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