StanfordCPPLib
Public Member Functions | Protected Member Functions | List of all members
ErrorException Class Reference


This exception is thrown by calls to the error function. More...

#include "error.h"

Inheritance diagram for ErrorException:

Public Member Functions

 ErrorException(string msg)
 Creates a new ErrorException with the given error message. More...
 
~ErrorException() noexcept=default
 Frees any memory allocated by the exception. More...
 
void dump() const
 Prints the exception to the standard error stream (cerr), including its message and stack trace if any. More...
 
void dump(std::ostream &out) const
 Prints the exception to the given output stream, including its message and stack trace if any. More...
 
string getKind() const
 Returns what kind of exception this is. More...
 
string getMessage() const
 Returns the exception's error message as passed to its constructor. More...
 
string getStackTrace() const
 Returns a stack trace for this exception as a multi-line string. More...
 
bool hasStackTrace() const
 Returns whether this exception has a non-empty stack trace. More...
 
void setKind(string kind)
 Sets what kind of exception this is. More...
 
const char * what() const noexcept
 Returns the exception's error message as a C string. More...
 

Protected Member Functions

void setStackTrace(string stackTrace)
 Sets this exception's stack trace to the given multi-line string. More...
 

Detailed Description


This exception is thrown by calls to the error function.

Typical code for catching errors looks like this:

     try {
        ... code in which an error might occur ...
     } catch (ErrorException& ex) {
        ... code to handle the error condition ...
     }
*

If an ErrorException is thrown at any point in the range of the try (including in functions called from that code), control will jump immediately to the error handler.

Constructor & Destructor Documentation

◆ ErrorException()

ErrorException ( string  msg)

Creates a new ErrorException with the given error message.

◆ ~ErrorException()

virtual ~ErrorException ( )
virtualdefaultnoexcept

Frees any memory allocated by the exception.

Member Function Documentation

◆ dump() [1/2]

void dump ( ) const
virtual

Prints the exception to the standard error stream (cerr), including its message and stack trace if any.

◆ dump() [2/2]

void dump ( std::ostream &  out) const
virtual

Prints the exception to the given output stream, including its message and stack trace if any.

◆ getKind()

string getKind ( ) const
virtual

Returns what kind of exception this is.

In general this returns "error", but in some cases we catch other kinds of exceptions (like thrown ints or strings) and wrap them up as ErrorExceptions. In such cases, the kind will be "int" or "string" etc.

◆ getMessage()

string getMessage ( ) const
virtual

Returns the exception's error message as passed to its constructor.

◆ getStackTrace()

string getStackTrace ( ) const
virtual

Returns a stack trace for this exception as a multi-line string.

See exceptions.h/cpp for descriptions of the format. Not every exception has a proper stack trace, based on when/why it was thrown, platform incompatibilities, and other issues; use hasStackTrace to check if a given exception's stack trace is populated.

◆ hasStackTrace()

bool hasStackTrace ( ) const
virtual

Returns whether this exception has a non-empty stack trace.

Not every exception has a proper stack trace, based on when/why it was thrown, platform incompatibilities, and other issues; use hasStackTrace to check if a given exception's stack trace is populated.

◆ setKind()

void setKind ( string   kind)

Sets what kind of exception this is.

Default is "error".

◆ setStackTrace()

void setStackTrace ( string   stackTrace)
protected

Sets this exception's stack trace to the given multi-line string.

◆ what()

const char * what ( ) const
virtualnoexcept

Returns the exception's error message as a C string.