Chaste Commit::1fd4e48e3990e67db148bc1bc4cf6991a0049d0c
Exception Class Reference

#include <Exception.hpp>

+ Inheritance diagram for Exception:
+ Collaboration diagram for Exception:

Public Member Functions

 Exception (const std::string &rMessage, const std::string &rFilename, unsigned lineNumber)
 
virtual ~Exception ()=default
 
std::string GetMessage () const
 
std::string GetShortMessage () const
 
std::string CheckShortMessage (const std::string &rExpected) const
 
std::string CheckShortMessageContains (const std::string &rExpected) const
 
virtual const char * what () const noexcept override
 

Static Public Member Functions

static void Terminate (const std::string &rMessage, const std::string &rFilename, unsigned lineNumber)
 

Protected Member Functions

void SetMessage (const std::string &rMessage, const std::string &rFilename, unsigned lineNumber)
 

Private Attributes

std::string mMessage
 
std::string mShortMessage
 

Detailed Description

Exception class. All exceptions thrown by this code are currently instances of this class.

Definition at line 64 of file Exception.hpp.

Constructor & Destructor Documentation

◆ Exception()

Exception::Exception ( const std::string &  rMessage,
const std::string &  rFilename,
unsigned  lineNumber 
)

Construct an exception with a message string.

Parameters
rMessagethe message
rFilenamewhich source file threw the exception
lineNumberwhich line number of the source file threw the exception

Definition at line 53 of file Exception.cpp.

References SetMessage().

◆ ~Exception()

virtual Exception::~Exception ( )
virtualdefault

Virtual destructor

Member Function Documentation

◆ CheckShortMessage()

std::string Exception::CheckShortMessage ( const std::string &  rExpected) const

Helper method for checking we have the right exception.

Returns
an empty string when the expected message matches. Checks that mShortMessage matches that given, and a suitable error message string if not.
Parameters
rExpectedthe expected value of mShortMessage

Definition at line 98 of file Exception.cpp.

References mShortMessage.

◆ CheckShortMessageContains()

std::string Exception::CheckShortMessageContains ( const std::string &  rExpected) const

Helper method for checking we have the right exception.

Returns
an empty string when the message contains the expected string. Checks that mShortMessage contains the given string, and returns a suitable error message string if not.
Parameters
rExpectedsome expected substring of mShortMessage

Definition at line 108 of file Exception.cpp.

References mShortMessage.

◆ GetMessage()

std::string Exception::GetMessage ( ) const

Get the message associated with the exception with file and line number

Returns
The message set when the exception was thrown including file and line number information

Definition at line 84 of file Exception.cpp.

References mMessage.

◆ GetShortMessage()

std::string Exception::GetShortMessage ( ) const

Get the message associated with the exception

Returns
The message text set when the exception was thrown.

Definition at line 89 of file Exception.cpp.

References mShortMessage.

◆ SetMessage()

void Exception::SetMessage ( const std::string &  rMessage,
const std::string &  rFilename,
unsigned  lineNumber 
)
protected

Allow subclasses to reset the exception message after construction of the base class, if desired.

Parameters
rMessagethe message
rFilenamewhich source file threw the exception
lineNumberwhich line number of the source file threw the exception

Definition at line 66 of file Exception.cpp.

References ChasteSourceRootDir(), mMessage, mShortMessage, and ChastePosixPathFixer::ToPosix().

Referenced by Exception().

◆ Terminate()

void Exception::Terminate ( const std::string &  rMessage,
const std::string &  rFilename,
unsigned  lineNumber 
)
static

Level 4 error (Termination). Execution cannot continue from this point and hence should be terminated (even when running with NDEBUG or in parallel).

Parameters
rMessageAn error message to appear on the screen
rFilenamewhich source file produced the termination error
lineNumberwhich line number of the source file produced the termination error

Definition at line 119 of file Exception.cpp.

◆ what()

const char * Exception::what ( ) const
overridevirtualnoexcept

Override of std::runtime_error - returns the error message

Returns
A pointer to a null-terminated character sequence.

Definition at line 94 of file Exception.cpp.

References mMessage.

Member Data Documentation

◆ mMessage

std::string Exception::mMessage
private

Full exception message - includes file and line number.

Definition at line 147 of file Exception.hpp.

Referenced by GetMessage(), SetMessage(), and what().

◆ mShortMessage

std::string Exception::mShortMessage
private

Short exception message - just text of the exception.

Definition at line 148 of file Exception.hpp.

Referenced by CheckShortMessage(), CheckShortMessageContains(), GetShortMessage(), and SetMessage().


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