mxlib
c++ tools for analyzing astronomical data and other tasks by Jared R. Males. [git repo]
Loading...
Searching...
No Matches
mx::exception< verboseT > Class Template Reference

template<class verboseT = verbose::d>
class mx::exception< verboseT >

Augments an exception with the source file and line.

Template Parameters
baseexceptis the base class exception which takes a string as constructor argument

Definition at line 41 of file exception.hpp.

#include <error/exception.hpp>

Public Member Functions

 exception (const std::source_location loc=std::source_location::current())
 Constructor with location only.
 exception (const std::string &msg, const std::source_location loc=std::source_location::current())
 Constructor with message.
 exception (error_t code, const std::string &msg, const std::source_location loc=std::source_location::current())
 Constructor with message and cod.
 exception (error_t code, const std::source_location loc=std::source_location::current())
 Constructor with code.
virtual const char * what () const noexcept
 Get the what string.
const std::string & message () const
 Get the message.
const std::string file_name () const
 Get the source file.
int line () const
 Get the source line.
error_t code () const
 Get the error code.

Protected Attributes

std::string m_what
 The full what message (message + file information).
error_t m_code { error_t::exception }
 The error_t code.
std::string m_message
 The explanatory message.

Constructor & Destructor Documentation

◆ exception() [1/4]

template<class verboseT = verbose::d>
mx::exception< verboseT >::exception ( const std::source_location loc = std::source_location::current())
inlineexplicit

Constructor with location only.

Parameters
[in]loc[opt] the location where this was thrown

Definition at line 56 of file exception.hpp.

References mx::error_message(), m_code, and m_what.

◆ exception() [2/4]

template<class verboseT = verbose::d>
mx::exception< verboseT >::exception ( const std::string & msg,
const std::source_location loc = std::source_location::current() )
inlineexplicit

Constructor with message.

Parameters
[in]msgthe error description message)
[in]loc[opt] the location where this was thrown

Definition at line 66 of file exception.hpp.

References mx::error_message(), m_code, m_message, and m_what.

◆ exception() [3/4]

template<class verboseT = verbose::d>
mx::exception< verboseT >::exception ( error_t code,
const std::string & msg,
const std::source_location loc = std::source_location::current() )
inline

Constructor with message and cod.

Parameters
[in]codea descriptive error code
[in]msgthe error description (what message)
[in]loc[opt] the location where this was thrown

Definition at line 77 of file exception.hpp.

References code(), mx::error_message(), m_code, m_message, and m_what.

◆ exception() [4/4]

template<class verboseT = verbose::d>
mx::exception< verboseT >::exception ( error_t code,
const std::source_location loc = std::source_location::current() )
inline

Constructor with code.

The message is filled in using errorMessage.

The what() message becomes "code_message (code) [file line]".

Parameters
[in]codea descriptive error code
[in]loc[opt] the location where this was thrown

Definition at line 91 of file exception.hpp.

References code(), mx::error_message(), m_code, and m_what.

Member Function Documentation

◆ code()

template<class verboseT = verbose::d>
error_t mx::exception< verboseT >::code ( ) const
inline

Get the error code.

Returns
the value of m_code

Definition at line 139 of file exception.hpp.

References m_code.

Referenced by exception(), exception(), mx::ioutils::dir_exists_is(), mx::ioutils::exists(), and unitTest::error_exception_test::TEST_CASE().

◆ file_name()

template<class verboseT = verbose::d>
const std::string mx::exception< verboseT >::file_name ( ) const
inline

Get the source file.

Returns
the value of m_location.file_name()

Definition at line 121 of file exception.hpp.

Referenced by unitTest::error_exception_test::TEST_CASE().

◆ line()

template<class verboseT = verbose::d>
int mx::exception< verboseT >::line ( ) const
inline

Get the source line.

Returns
the value of m_location.line()

Definition at line 130 of file exception.hpp.

Referenced by unitTest::error_exception_test::TEST_CASE().

◆ message()

template<class verboseT = verbose::d>
const std::string & mx::exception< verboseT >::message ( ) const
inline

Get the message.

Returns
the value of m_message

Definition at line 112 of file exception.hpp.

References m_message.

Referenced by unitTest::error_exception_test::TEST_CASE().

◆ what()

template<class verboseT = verbose::d>
virtual const char * mx::exception< verboseT >::what ( ) const
inlinevirtualnoexcept

Get the what string.

Returns
the value of m_what.c_str()

Definition at line 103 of file exception.hpp.

References m_what.

Referenced by unitTest::error_exception_test::TEST_CASE().

Member Data Documentation

◆ m_code

template<class verboseT = verbose::d>
error_t mx::exception< verboseT >::m_code { error_t::exception }
protected

The error_t code.

Definition at line 46 of file exception.hpp.

Referenced by exception(), exception(), exception(), exception(), and code().

◆ m_message

template<class verboseT = verbose::d>
std::string mx::exception< verboseT >::m_message
protected

The explanatory message.

Definition at line 48 of file exception.hpp.

Referenced by exception(), exception(), and message().

◆ m_what

template<class verboseT = verbose::d>
std::string mx::exception< verboseT >::m_what
protected

The full what message (message + file information).

Definition at line 44 of file exception.hpp.

Referenced by exception(), exception(), exception(), exception(), and what().


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