stator
A math, geometry, and utility library
Public Member Functions | List of all members
stator::Exception Class Reference

An exception class that also appears to function like an ostream object. More...

#include <exception.hpp>

Inheritance diagram for stator::Exception:

Public Member Functions

 Exception (int line, const char *file, const char *funcname) throw ()
 Constructor called by the stator_throw() macro. More...
 
 Exception (const Exception &e)
 Copy constructor. More...
 
 ~Exception () throw ()
 
template<class T >
Exceptionoperator<< (const T &m)
 The stream operator engine for the class. More...
 
const char * what () const throw ()
 Get the stored message from the class. More...
 

Detailed Description

This class is thrown using the stator_throw() macro like so :-

stator_throw() << "My custom error message";

An important note, you should always catch the exception classes by reference, as this prevents type conversions to base classes and maintains the virtual overrides.

try {
//Some code which may throw a stator exception.
} catch (stator::Exception& ex) {
//Some response to the exception
}

Please note, as the stator::Exception class inherits from std::exception, you can catch it using a more generic catch statement

try {
//Some code which may throw a stator exception.
} catch (std::exception& ex) {
//Some response to the exception
}

To allow the combining of multiple exception types, all exceptions should inherit virtually from base exception types.

Definition at line 66 of file exception.hpp.

Constructor & Destructor Documentation

◆ Exception() [1/2]

stator::Exception::Exception ( int  line,
const char *  file,
const char *  funcname 
)
throw (
)
inline
Parameters
lineThe line number in the source file.
fileThe name of the source file.
funcnameThe name of the function throwing the exception.

Definition at line 74 of file exception.hpp.

◆ Exception() [2/2]

stator::Exception::Exception ( const Exception e)
inline

Please catch exceptions by reference, they should not be copied except at the throw site.

Definition at line 86 of file exception.hpp.

◆ ~Exception()

stator::Exception::~Exception ( )
throw (
)
inline

Definition at line 89 of file exception.hpp.

Member Function Documentation

◆ operator<<()

template<class T >
Exception& stator::Exception::operator<< ( const T &  m)
inline

Definition at line 94 of file exception.hpp.

◆ what()

const char* stator::Exception::what ( ) const
throw (
)
inline

This returns a pointer to a traditional C-type string. This is guaranteed to be valid at least until the exception object from which it is obtained is destroyed or until a non-const member function of the exception object is called.

This is not reentrant and is annoyingly C-like, but it is in the standard.

Definition at line 109 of file exception.hpp.


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