Skip to content

callstack_exception.hpp

mhahnFr edited this page Feb 20, 2024 · 5 revisions

This header defines an exception capable to print its construction stacktrace using the CallstackLibrary.

Definitions

LCS_NOEXCEPT

Defines that a function must not throw any exception - throw() in C++98 and noexcept in C++11 and newer.

LCS_CONSTEXPR

Defines that a function creates a constant expression - not used prior to C++11, where the macro becomes constexpr.

LCS_OVERRIDE

Marks methods that override a method from a parent class - not used prior to C++11, where the macro becomes override.

LCS_NULL

Defines a pointer to nothing - NULL in C++98 and nullptr in C++11 and newer.

namespace lcs

The namespace all C++ classes of this library can be found in.

class exception: public std::exception

This class defines an exception capable to create and print the callstack where it initially has been constructed - usually where it was thrown.

Constructors

explicit exception(const bool printStacktrace = true) LCS_NOEXCEPT

Trivial default constructor. The passed boolean value indicates whether to automatically append the stacktrace to the exception message.

explicit exception(const char* message, const bool printStacktrace = true) LCS_NOEXCEPT

Constructs an exception with the given message. The passed boolean value indicates whether to automatically append the stacktrace to the exception message.

The passed message is copied.

explicit exception(const std::string& message, const bool printStacktrace = true) LCS_NOEXCEPT

Constructs an exception with the given message. The passed boolean value indicates whether to automatically append the stacktrace to the exception message.

exception(const exception& other)

Trivial copy constructor.

exception(exception&&)

Trivial move constructor.

Only available if a compiler supporting C++11 is used.

Destructor

virtual ~exception() LCS_NOEXCEPT Trivial virtual destructor.

Methods

virtual const char* what() const LCS_NOEXCEPT LCS_OVERRIDE

Returns the exception message.

If shouldPrintStacktrace is set to true the stacktrace of the construction of this exception object is appended to the returned string.

void printStacktrace(std::ostream& out, const bool printMessage = true) const

Prints the stacktrace where this exception object has been constructed to the given output stream. The passed boolean value indicates whether to print the exception message as well.

void setPrintStacktrace(const bool printStacktrace) LCS_NOEXCEPT

Sets whether to automatically append the stacktrace to the exception message.

LCS_CONSTEXPR bool getPrintStacktrace() const LCS_NOEXCEPT

Returns whether the stacktrace is automatically appended to the exception message.

LCS_CONSTEXPR callstack& getCallstack() const LCS_NOEXCEPT

Returns the callstack object of where this exception object has been constructed.

LCS_CONSTEXPR const std::string& getMessage() const LCS_NOEXCEPT

Returns the message of this exception.

Variables

const std::string message

The message that can be optionally be thrown.

bool shouldPrintStacktrace

Indicates whether to automatically translate and add the callstack to the exception message.

mutable callstack cs

The callstack where this exception object was constructed.

mutable std::string messageBuffer

The message buffer.

Clone this wiki locally