rcolyer.net
RC Lib  Version 202403231100
Public Member Functions | List of all members
RC::ErrorMsg Class Reference

An exception class that records where the exception was thrown and provides a stack trace. More...

#include <Errors.h>

Inheritance diagram for RC::ErrorMsg:
RC::ErrorMsgBounds RC::ErrorMsgCast RC::ErrorMsgFatal RC::ErrorMsgFile RC::ErrorMsgMemory RC::ErrorMsgNet RC::ErrorMsgNull

Public Member Functions

 ErrorMsg (const char *new_err_msg=NULL, const char *filename=NULL, int line_number=0) noexcept
 The default constructor. More...
 
virtual const char * GetError () const noexcept
 Provides the reason given for the error. More...
 
virtual const char * GetType () const noexcept
 Provides the type of the exception if this is a subclass. More...
 
virtual bool IsError (const char *test_err) const noexcept
 Return true if the the reason for the exception matches test_err. More...
 
virtual const char * what () const noexcept
 Returns a full descriptive error message with reason, source location, and stack trace. More...
 

Detailed Description

An exception class that records where the exception was thrown and provides a stack trace.

Use with the macro Throw_RC_Error("Reason"); to automatically pick up the source filename and line number. This exception should be used liberally any time an error would be informative for resolving a bug.

Stack tracing is implemented for Linux and Windows. For Linux with g++ or clang compile with -rdynamic for full symbols in the stack trace output from what(). For Windows symbols cannot be automatically provided with mingw, but the addresses provided in what() can be resolved by providing them as stdin to "addr2line -pfe myprogram.exe" for any program compiled with -ggdb.

Constructor & Destructor Documentation

◆ ErrorMsg()

RC::ErrorMsg::ErrorMsg ( const char *  new_err_msg = NULL,
const char *  filename = NULL,
int  line_number = 0 
)
inlinenoexcept

The default constructor.

Use the convenience macro Throw_RC_Error("Reason"); which uses FILE and LINE to extract the location of the throw.

Parameters
new_err_msgThe reason for the exception.
filenameThe source code file that the exception was triggered in.
line_numberThe source code line number that the exception was triggered on.

Member Function Documentation

◆ GetError()

virtual const char* RC::ErrorMsg::GetError ( ) const
inlinevirtualnoexcept

Provides the reason given for the error.

Returns
The reason for the exception being thrown.

◆ GetType()

virtual const char* RC::ErrorMsg::GetType ( ) const
inlinevirtualnoexcept

Provides the type of the exception if this is a subclass.

An empty string is returned for the base class.

Returns
The exception type defined in a subclass.

◆ IsError()

virtual bool RC::ErrorMsg::IsError ( const char *  test_err) const
inlinevirtualnoexcept

Return true if the the reason for the exception matches test_err.

Parameters
test_errAn error message to compare with the reason given in the constructor.
Returns
True if the error messages are identical.

◆ what()

virtual const char* RC::ErrorMsg::what ( ) const
inlinevirtualnoexcept

Returns a full descriptive error message with reason, source location, and stack trace.

Note: The stack trace is only available if on a supported system, and if the RC_NO_STACKTRACE option was not given in RCconfig.h


The documentation for this class was generated from the following file:
email address
— (c) 2015