The Sparta Modeling Framework
Loading...
Searching...
No Matches
sparta::SpartaException Class Reference

Used to construct and throw a standard C++ exception. Inherits from std::exception. More...

#include <SpartaException.hpp>

Inheritance diagram for sparta::SpartaException:
Collaboration diagram for sparta::SpartaException:

Public Member Functions

 SpartaException ()
 Construct a SpartaException object with empty reason.
 
 SpartaException (const std::string &reason)
 Construct a SpartaException object.
 
 SpartaException (const SpartaException &orig)
 Copy construct a SpartaException object.
 
virtual ~SpartaException () noexcept
 Destroy!
 
const char * what () const noexcept
 Overload from std::exception.
 
std::string backtrace () const noexcept
 Returns the backtrace at the time this exception was generated.
 
std::string rawReason () const
 Return the raw reason without file, line information.
 
template<class T >
SpartaExceptionoperator<< (const T &msg)
 Append additional information to the message.
 

Detailed Description

Used to construct and throw a standard C++ exception. Inherits from std::exception.

Warning
Creates a backtrace, which introduces much overhead. Whenever possible, avoid constructing the exception until the exact line of where the error condition is detected or a neighboring line which is not separated by any functional code from the place where the error condition is detected.
Do not construct this exception unless it is going to be thrown

Definition at line 63 of file SpartaException.hpp.

Constructor & Destructor Documentation

◆ SpartaException() [1/2]

sparta::SpartaException::SpartaException ( )

Construct a SpartaException object with empty reason.

Note
All other non-copy and non-move constructors must delegate to this constructor so that breakpoints can easily be placed on one symbol to catch sparta Exceptions

Reason can be populated later with the insertion operator.

◆ SpartaException() [2/2]

sparta::SpartaException::SpartaException ( const std::string &  reason)

Construct a SpartaException object.

Parameters
reasonThe reason for the exception
Note
Delegated to SpartaException so that debugger breakpoints may be more easily be placed.

Member Function Documentation

◆ operator<<()

template<class T >
SpartaException & sparta::SpartaException::operator<< ( const T &  msg)
inline

Append additional information to the message.

Parameters
msgThe addition info
Returns
This exception object

Usage:

int bad_company = 4;
e << ": this is bad: " << bad_company;
Used to construct and throw a standard C++ exception. Inherits from std::exception.

or you can do this:

int bad_company = 4;
throw sparta::SpartaException e("Oh uh") << ": this is bad: " << bad_company;

but it's not as pretty.

Definition at line 134 of file SpartaException.hpp.

◆ rawReason()

std::string sparta::SpartaException::rawReason ( ) const
inline

Return the raw reason without file, line information.

Returns
The raw reason, no file information

Definition at line 111 of file SpartaException.hpp.

◆ what()

const char * sparta::SpartaException::what ( ) const
inlinenoexcept

Overload from std::exception.

Returns
Const char * of the exception reason

Definition at line 97 of file SpartaException.hpp.


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