Class to handle errors and exceptions in a simple, consistent stream-based manner. More...
Public Member Functions | |
error (const string &title) | |
Construct from title string. More... | |
error (const dictionary &errDict) | |
Construct from dictionary. More... | |
error (const error &err) | |
Copy construct. More... | |
virtual | ~error () noexcept |
Destructor. More... | |
string | message () const |
The accumulated error message. More... | |
void | clear () const |
Clear any messages. More... | |
const string & | functionName () const |
const string & | sourceFileName () const |
label | sourceFileLineNumber () const |
bool | throwing () const |
Return the current exception throwing (on or off) More... | |
bool | throwExceptions (bool doThrow) |
Activate/deactivate exception throwing. More... | |
bool | throwExceptions () |
Activate exception throwing. More... | |
bool | dontThrowExceptions () |
Deactivate exception throwing. More... | |
OSstream & | operator() (const string &functionName) |
Define basic print message. More... | |
OSstream & | operator() (const char *functionName, const char *sourceFileName, const int sourceFileLineNumber=0) |
Define basic print message. More... | |
OSstream & | operator() (const string &functionName, const char *sourceFileName, const int sourceFileLineNumber=0) |
Define basic print message. More... | |
OSstream & | operator() () |
Explicit convert to OSstream for << operations. More... | |
operator OSstream & () | |
Convert to OSstream. More... | |
operator dictionary () const | |
Create and return a dictionary representation of the error. More... | |
void | exit (const int errNo=1) |
Exit : can be called for any error to exit program. More... | |
void | abort () |
Abort : used to stop code for fatal errors. More... | |
void | write (Ostream &os, const bool includeTitle=true) const |
Print error message. More... | |
Static Public Member Functions | |
static void | warnAboutAge (const char *what, const int version) |
Emit warning on stderr about something being old. More... | |
static void | safePrintStack (std::ostream &os) |
static void | printStack (Ostream &os) |
Helper function to print a stack. More... | |
Protected Attributes | |
string | functionName_ |
string | sourceFileName_ |
label | sourceFileLineNumber_ |
bool | throwExceptions_ |
OStringStream * | messageStreamPtr_ |
Additional Inherited Members | |
Message type, or error severity flags. More... |
Class to handle errors and exceptions in a simple, consistent stream-based manner.
The error class is globally instantiated with a title string. Errors, messages and other data are piped to the messageStream class in the standard manner. Manipulators are supplied for exit and abort that may terminate the program or throw an exception depending on whether the exception handling has been switched on (off by default).
Construct from title string.
Definition at line 75 of file error.C.
References Foam::endl(), error::exit(), IOstream::good(), error::messageStreamPtr_, Foam::nl, and Foam::Perr.
|
explicit |
Construct from dictionary.
Definition at line 95 of file error.C.
References Foam::endl(), error::exit(), IOstream::good(), error::messageStreamPtr_, Foam::nl, and Foam::Perr.
|
static |
Emit warning on stderr about something being old.
what | description for the warning |
version | is the old version (YYMM) for determining the age in months compared to the current OpenFOAM version as conveyed by the foamVersion::api value. |
Definition at line 40 of file error.C.
References Foam::foamVersion::api, Foam::endl(), and Foam::foamVersion::version.
Referenced by Foam::expandLeadingTilde(), and timeControl::read().
Foam::string message | ( | ) | const |
The accumulated error message.
Definition at line 214 of file error.C.
Referenced by snappyLayerDriver::addLayers(), and motionSmootherAlgo::checkMesh().
void clear | ( | ) | const |
Clear any messages.
Definition at line 220 of file error.C.
Referenced by motionSmootherAlgo::checkMesh().
|
inline |
Definition at line 122 of file error.H.
References error::functionName_.
|
inline |
Definition at line 127 of file error.H.
References error::sourceFileName_.
|
inline |
Definition at line 132 of file error.H.
References error::sourceFileLineNumber_.
|
inline |
Return the current exception throwing (on or off)
Definition at line 138 of file error.H.
References error::throwExceptions_.
Activate/deactivate exception throwing.
Definition at line 145 of file error.H.
Referenced by if(), IOobjectList::IOobjectList(), and functionObjectList::read().
|
inline |
|
inline |
Foam::OSstream & operator() | ( | const string & | functionName | ) |
Foam::OSstream & operator() | ( | const char * | functionName, |
const char * | sourceFileName, | ||
const int | sourceFileLineNumber = 0 |
||
) |
Foam::OSstream & operator() | ( | const string & | functionName, |
const char * | sourceFileName, | ||
const int | sourceFileLineNumber = 0 |
||
) |
|
inline |
Explicit convert to OSstream for << operations.
Definition at line 192 of file error.H.
Referenced by IOerror::operator()().
operator dictionary | ( | ) | const |
Create and return a dictionary representation of the error.
|
static |
Helper function to print a stack, used when OpenFOAM IO not yet initialised.
Definition at line 32 of file dummyPrintStack.C.
|
static |
Helper function to print a stack.
Definition at line 36 of file dummyPrintStack.C.
Referenced by messageStream::masterStream(), and Foam::reduce().
void exit | ( | const int | errNo = 1 | ) |
Exit : can be called for any error to exit program.
Redirects to abort() when FOAM_ABORT is on.
Definition at line 298 of file error.C.
References Foam::hasEnv().
Referenced by error::error(), Foam::exit(), and if().
void abort | ( | ) |
Abort : used to stop code for fatal errors.
Prints stack before exiting.
Definition at line 304 of file error.C.
Referenced by Foam::abort().
Print error message.
Definition at line 310 of file error.C.
References IOstream::bad(), messageStream::level, and Foam::nl.
Referenced by Foam::operator<<(), argList::parse(), and functionObjectList::read().
|
protected |
Definition at line 79 of file error.H.
Referenced by error::functionName().
|
protected |
Definition at line 80 of file error.H.
Referenced by error::sourceFileName().
|
protected |
Definition at line 81 of file error.H.
Referenced by error::sourceFileLineNumber().
|
protected |
Definition at line 82 of file error.H.
Referenced by error::throwing().
|
protected |
Definition at line 83 of file error.H.
Referenced by error::error().