Base Framework
Classes | Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
Exception Class Reference

The general exception class. More...

#include <base/Exception.h>

Inherited by AmbiguousRegistration, ArgumentException, CacheException, CastException, ConcurrencyException, Construct, ContainerException, DateException, Destruct, DOMException, DOMImplementation::EventException, ExpressionException, extension::RegistryException, FileSystemException, Group::GroupException, IncompatibleOperands, InvalidException, InvalidFormat, IOException, JSONException, LinkerException, LockException, Matrix< TYPE >::MatrixException, MultibyteException, NotImplemented, NotSupported, ObjectModelException, OpenCLException, OpenGLException, OutOfBounds, OutOfDomain, OutOfRange, Overflow, ParseException, Process::ProcessException, RegExp::RegExpException, ResourceException, RMIException, SAXException, SecurityException, SingletonException, StringException, Thread::ThreadException, ThreadKeyImpl::ThreadKeyException, ThreadPool::ThreadPoolException, TransformerException, Trustee::TrusteeException, Underflow, UnexpectedFailure, User::UserException, UserInterfaceException, Vector< TYPE >::VectorException, WebAssembly::WebAssemblyException, and YAMLException.

Classes

class  Hook
 
class  StackTrace
 

Public Types

enum  DumpOnThrow { DUMP_ON_THROW_NO = 0, DUMP_ON_THROW_EXCEPTION, DUMP_ON_THROW_STACK }
 
typedef void(* ExceptionHandler) (const Exception *exception)
 

Public Member Functions

 Exception () noexcept
 
 Exception (const char *message) noexcept
 
 Exception (const Type &type) noexcept
 
 Exception (const char *message, const Type &type) noexcept
 
 Exception (const Exception &copy) noexcept
 
 Exception (Exception &&move) noexcept
 
unsigned int getCause () const noexcept
 
void setCause (unsigned int cause) noexcept
 
unsigned int getError () const noexcept
 
void setError (unsigned int error) noexcept
 
const char * getMessage () const noexcept
 
void setMessage (const char *message) noexcept
 
template<decltype(sizeof(void *)) SIZE>
void setMessage (const char(&_message)[SIZE]) noexcept
 
virtual Type getThisType () const noexcept
 
const TypegetType () const noexcept
 
void setType (const Type &type) noexcept
 
virtual bool isCommonException () const noexcept
 
OwnedNativeString getHTML () const
 
virtual ~Exception () noexcept
 

Static Public Member Functions

static void onThrow (const Exception &exception) noexcept
 
static void rethrow ()
 
static bool getDumpExceptions () noexcept
 
static void setDumpExceptions (bool _dumpExceptions) noexcept
 
static ExceptionHandler setExceptionHandler (ExceptionHandler _exceptionHandler) noexcept
 
static bool hasPendingException () noexcept
 
static bool isUnwinding () noexcept
 
static unsigned int getPendingExceptions () noexcept
 
static const char * getStdExceptionName (const std::exception &e) noexcept
 
static Type getExceptionType () noexcept
 
static StackTrace getStackTrace ()
 
static void setDumpOnThrow (DumpOnThrow dumpOnThrow) noexcept
 

Static Public Attributes

static constexpr bool SUPPORTS_EXCEPTIONS = true
 

Detailed Description

The general exception class.

This is the base class of all exceptions supported by the framework. Normally exceptions do not raise exceptions themselves. It is highly advised against raising objects which are not specializations of Exception. Exceptions allow the developer to handle 'rare' conditions at runtime in a safe manner. An exception doesn't have to be indicating an error but normally does. Uncaught exceptions will terminate the executing context with an error (in the case of the main context the entire application is terminated).

Version
1.2
Examples
testsuite/Array.cpp, testsuite/digest.cpp, testsuite/ftp.cpp, testsuite/IEEE1394.cpp, and testsuite/ls.cpp.

Member Typedef Documentation

◆ ExceptionHandler

typedef void(* Exception::ExceptionHandler) (const Exception *exception)

Callback for exception.

Constructor & Destructor Documentation

◆ Exception() [1/6]

Exception::Exception ( )
noexcept

Initializes the exception object without an associated message and type identity.

◆ Exception() [2/6]

Exception::Exception ( const char *  message)
noexcept

Initializes the exception object.

Parameters
messageAn NULL-terminated string (ASCII).

◆ Exception() [3/6]

Exception::Exception ( const Type type)
noexcept

Initializes the exception object without an associated message.

Parameters
typeThe identity of the type.

◆ Exception() [4/6]

Exception::Exception ( const char *  message,
const Type type 
)
noexcept

Initializes the exception object.

void myMethod()
{
if (!condition) {
_throw Exception("My short message.", this);
}
...
}
Parameters
messageAn NULL-terminated string (ASCII).
typeThe identity of the type.

◆ Exception() [5/6]

Exception::Exception ( const Exception copy)
noexcept

Copy constructor.

Parameters
exceptionThe exception object to be copied.

◆ Exception() [6/6]

Exception::Exception ( Exception &&  move)
noexcept

Move constructor.

Parameters
exceptionThe exception object to be moved.

◆ ~Exception()

virtual Exception::~Exception ( )
virtualnoexcept

Destroys exception object.

Member Function Documentation

◆ getCause()

unsigned int Exception::getCause ( ) const
inlinenoexcept

Returns the associated cause. 0 indicates an unspecified cause.

◆ getDumpExceptions()

static bool Exception::getDumpExceptions ( )
inlinestaticnoexcept

Returns true if stack traces for new exceptions are printed.

◆ getError()

unsigned int Exception::getError ( ) const
inlinenoexcept

Returns the associated native error code. 0 if no error.

◆ getExceptionType()

static Type Exception::getExceptionType ( )
staticnoexcept

Returns the type of the caught exception.

Returns
An uninitialized type is returned if no exception has been caught or this method isn't supported.

◆ getHTML()

OwnedNativeString Exception::getHTML ( ) const

Returns HTML information.

◆ getMessage()

const char* Exception::getMessage ( ) const
inlinenoexcept

Returns the message associated with the exception.

Returns
The message associated with the exception.
Examples
testsuite/du.cpp, testsuite/echod.cpp, testsuite/eval.cpp, testsuite/IEEE1394.cpp, testsuite/ln.cpp, testsuite/ping.cpp, testsuite/rm.cpp, and testsuite/server.cpp.

◆ getPendingExceptions()

static unsigned int Exception::getPendingExceptions ( )
staticnoexcept

Returns the number of currently pending/unhandled exceptions.

◆ getStackTrace()

static StackTrace Exception::getStackTrace ( )
static

Returns the stack trace for the last constructed exception. Avoid constructing exception that are not thrown as these will hide the true exception.

Returns
Can return nullptr if exception is unknown. Do NOT keep the pointers outside scope.

◆ getStdExceptionName()

static const char* Exception::getStdExceptionName ( const std::exception &  e)
staticnoexcept

Returns description for well-known Std C++ exceptions.

◆ getThisType()

virtual Type Exception::getThisType ( ) const
virtualnoexcept

Returns the type of the exception.

◆ getType()

const Type& Exception::getType ( ) const
inlinenoexcept

Returns the identity of the type which raised the exception.

◆ hasPendingException()

static bool Exception::hasPendingException ( )
staticnoexcept

Returns true if an exception is pending.

◆ isCommonException()

virtual bool Exception::isCommonException ( ) const
virtualnoexcept

Returns true if exception is generally an externally triggered exception that can be suppressed and handled directly. Internal exceptions like NullPointer should not be handled which is the default behavior. E.g. out of resource, EOF, parsing issues, and similar.

Reimplemented in JSONException, EndOfFile, InvalidFormat, FileNotFound, TimedOut, and YAMLException.

◆ isUnwinding()

static bool Exception::isUnwinding ( )
staticnoexcept

Returns true if the stack is currently being unwinded due to a raised exception.

See also
getExceptionType
Returns
False if not supported.

◆ onThrow()

static void Exception::onThrow ( const Exception exception)
staticnoexcept

Called on throw.

◆ rethrow()

static void Exception::rethrow ( )
static

Rethrows exception. Throws Exception if there is no current exception.

◆ setCause()

void Exception::setCause ( unsigned int  cause)
inlinenoexcept

Sets the cause. 0 indicates an unspecified cause.

◆ setDumpExceptions()

static void Exception::setDumpExceptions ( bool  _dumpExceptions)
inlinestaticnoexcept

Enables printing of stack traces when exceptions are constructed.

◆ setDumpOnThrow()

static void Exception::setDumpOnThrow ( DumpOnThrow  dumpOnThrow)
staticnoexcept

Sets whether or not to dump expection on throw.

◆ setError()

void Exception::setError ( unsigned int  error)
inlinenoexcept

Sets the native error code. 0 indicates no error.

◆ setExceptionHandler()

static ExceptionHandler Exception::setExceptionHandler ( ExceptionHandler  _exceptionHandler)
inlinestaticnoexcept

Sets exception handler.

◆ setMessage() [1/2]

void Exception::setMessage ( const char *  message)
inlinenoexcept

Associates the exception with the specified message.

◆ setMessage() [2/2]

template<decltype(sizeof(void *)) SIZE>
void Exception::setMessage ( const char(&)  _message[SIZE])
inlinenoexcept

Associates the exception with the specified message.

◆ setType()

void Exception::setType ( const Type type)
inlinenoexcept

Sets the identity of the type which raised the exception.

Exception::Exception
Exception() noexcept