Exception class that inherits from the standard C++ class std:exception
.
More...
#include <Exception.hpp>
Public Member Functions | |
virtual | ~Exception (void) |
Destructor. More... | |
Exception (void) | |
Empty constructor. Wont have a function name, filename, nor line number. Will have the call stack. More... | |
Exception (const std::exception &rhs) | |
Copy constructor from a standard exception to preserve the text in what() . Wont have a function name, filename, nor line number. Will have the call stack where the std::exception is converted to nocl::Exception . More... | |
Exception (const std::string &text) | |
Constructor with a text description to use when what() is called. Wont have a function name, filename, nor line number. Will have the call stack. More... | |
Exception (const std::string &func, const std::string &fname, const size_t linenum, const std::string &text) | |
Normal constructor for the exception class. More... | |
std::string | details (void) const |
Format the exception including the location and full call stack into a multi-line text string. More... | |
virtual const char * | what (void) const noexcept override |
Return the single-line message describing this exception. More... | |
Public Attributes | |
std::string | what_text |
Single line of text to return when what() is called. More... | |
std::string | function |
Function name. Depending on how the exception was created, this may be an empty string. More... | |
std::string | filename |
Filename. Depending on how the exception was created, this may be an empty string. More... | |
size_t | line_number |
Line number. Depending on how the exception was created, this may be zero. More... | |
VStr | call_stack |
Vector of strings showing the call stack at the time the nocl::Exception object was created. More... | |
Static Public Attributes | |
static std::string | log_filename |
Filename where exceptions created should be logged. More... | |
Exception class that inherits from the standard C++ class std:exception
.
In addition to the usual what()
call, these exception objects also stores the function name, filename, line number, and the full call stack where the exception was created.
To get the most details from your exceptions, make sure you use the constructor that uses the NOCL_WHERE macro to pass in all the necessary information.
For example:
Call details() on your exceptions to get a multi-line text description of the exception, which will include the exception text, the location where the exception happened, and the full call stack when the exception object was instantiated.
For example:
The result of calling "e.details()"
would be similar to this text block:
|
virtual |
Destructor.
nocl::Exception::Exception | ( | void | ) |
Empty constructor. Wont have a function name, filename, nor line number. Will have the call stack.
|
explicit |
Copy constructor from a standard exception to preserve the text in what()
. Wont have a function name, filename, nor line number. Will have the call stack where the std::exception
is converted to nocl::Exception
.
nocl::Exception::Exception | ( | const std::string & | text | ) |
Constructor with a text description to use when what() is called. Wont have a function name, filename, nor line number. Will have the call stack.
nocl::Exception::Exception | ( | const std::string & | func, |
const std::string & | fname, | ||
const size_t | linenum, | ||
const std::string & | text | ||
) |
Normal constructor for the exception class.
The first 3 parameters to this constructor are normally filled out by using the the NOCL_WHERE
macro. This is the constructor strongly suggested be used since it fills in all of the location details.
For example:
References details(), nocl::Logfile::get(), log_filename, and nocl::Logfile::ts().
std::string nocl::Exception::details | ( | void | ) | const |
Format the exception including the location and full call stack into a multi-line text string.
For example:
When the exception is caught, the details could be logged similar to this:
This would result in a multi-line text block such as:
std::endl
. References call_stack, filename, line_number, nocl::shorten_path_for_display(), and what().
Referenced by Exception(), and nocl::Application::run_message_loop().
|
overridevirtualnoexcept |
std::string nocl::Exception::what_text |
std::string nocl::Exception::function |
Function name. Depending on how the exception was created, this may be an empty string.
std::string nocl::Exception::filename |
size_t nocl::Exception::line_number |
VStr nocl::Exception::call_stack |
|
static |
Filename where exceptions created should be logged.
If set, a nocl::Logfile object is created and the exception is logged with the text returned by Exception::details().
Referenced by Exception(), and nocl::Logfile::log_nocl_exceptions().