26#ifndef error_exception_hpp
27#define error_exception_hpp
40template <
class verboseT = verbose::d>
50 std::source_location m_location;
56 explicit exception(
const std::source_location loc =
57 std::source_location::current() )
67 const std::source_location loc =
68 std::source_location::current() )
78 const std::string &msg,
79 const std::source_location loc =
80 std::source_location::current() )
92 const std::source_location loc =
93 std::source_location::current() )
103 virtual const char *
what() const noexcept
123 return m_location.file_name();
132 return m_location.line();
151 const std::exception &e
154 whats.push_back( e.what() );
158 std::rethrow_if_nested( e );
160 catch(
const std::exception &nestedException )
175 const std::string &message =
176 "exception(s) thrown" )
178 std::cerr << message <<
":\n";
179 std::cerr <<
" " << whats.back() <<
'\n';
180 for(
size_t n = 1; n < whats.size(); ++n )
182 std::cerr << std::string( 2,
' ' ) << std::string( ( n - 1 ) * 4,
' ' ) <<
"|-->" << whats[whats.size() - 1 - n]
Augments an exception with the source file and line.
exception(const std::source_location loc=std::source_location::current())
Constructor with location only.
std::string m_message
The explanatory message.
const std::string & message() const
Get the message.
error_t code() const
Get the error code.
exception(error_t code, const std::string &msg, const std::source_location loc=std::source_location::current())
Constructor with message and cod.
exception(const std::string &msg, const std::source_location loc=std::source_location::current())
Constructor with message.
exception(error_t code, const std::source_location loc=std::source_location::current())
Constructor with code.
const std::string file_name() const
Get the source file.
int line() const
Get the source line.
virtual const char * what() const noexcept
Get the what string.
std::string m_what
The full what message (message + file information).
error_t m_code
The error_t code.
The mxlib error reporting system.
error_t
The mxlib error codes.
@ exception
An exception was thrown.
void print_exceptions(std::vector< std::string > &whats, const std::string &message="exception(s) thrown")
Print nested exceptions to stderr, from the earliest to latest.
void unwind_exceptions(std::vector< std::string > &whats, const std::exception &e)
Extract the explanatory string of nested exceptions, placing them in a vector.