Class to handle errors and exceptions in a simple, consistent stream-based manner. More...
#include <OpenFOAM/error.H>
Class to handle errors and exceptions in a simple, consistent stream-based manner.
The error class is globaly 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 which may terminate the program or throw an exception depending of if the exception handling has beed switched on (off by default).
Definition at line 67 of file error.H.
Public Member Functions | |
error (const string &title) | |
Construct from title string.
| |
error (const dictionary &errDict) | |
Construct from dictionary.
| |
error (const error &err) | |
Construct as copy.
| |
virtual | ~error () throw () |
string | message () const |
const string & | functionName () const |
const string & | sourceFileName () const |
label | sourceFileLineNumber () const |
void | throwExceptions () |
void | dontThrowExceptions () |
OSstream & | operator() (const char *functionName, const char *sourceFileName, const int sourceFileLineNumber=0) |
Convert to Ostream.
| |
OSstream & | operator() (const string &functionName, const char *sourceFileName, const int sourceFileLineNumber=0) |
operator OSstream & () | |
Convert to Ostream.
| |
OSstream & | operator() () |
Explicitly convert to Ostream for << operations.
| |
operator dictionary () const | |
Create and return a dictionary.
| |
void | exit (const int errNo=1) |
Exit : can be called for any error to exit program. Prints stack.
| |
void | abort () |
Abort : used to stop code for fatal errors. Prints stack before.
| |
Static Public Member Functions | |
static void | printStack (Ostream &os) |
Helper function to print a stack.
| |
Protected Attributes | |
string | functionName_ |
string | sourceFileName_ |
label | sourceFileLineNumber_ |
bool | abort_ |
bool | throwExceptions_ |
OStringStream * | messageStreamPtr_ |
Friends | |
Ostream & | operator<< (Ostream &, const error &) |
Construct from title string.
Definition at line 36 of file error.C.
References Foam::endl(), error::exit(), IOstream::good(), error::messageStreamPtr_, and Foam::Perr.
error | ( | const dictionary & | errDict ) |
Construct from dictionary.
Definition at line 57 of file error.C.
References Foam::endl(), error::exit(), IOstream::good(), error::messageStreamPtr_, and Foam::Perr.
Foam::string message | ( | ) | const |
Definition at line 162 of file error.C.
Referenced by Foam::operator<<().
const string& functionName | ( | ) | const [inline]
|
Definition at line 109 of file error.H.
References error::functionName_.
Referenced by Foam::operator<<().
const string& sourceFileName | ( | ) | const [inline]
|
Definition at line 114 of file error.H.
References error::sourceFileName_.
Referenced by Foam::operator<<().
label sourceFileLineNumber | ( | ) | const [inline]
|
Definition at line 119 of file error.H.
References error::sourceFileLineNumber_.
Referenced by Foam::operator<<().
void throwExceptions | ( | ) | [inline]
|
Definition at line 124 of file error.H.
References error::throwExceptions_.
Referenced by Foam::tryCalc(), calcType::tryCalc(), calcType::tryInit(), calcType::tryPostCalc(), and calcType::tryPreCalc().
void dontThrowExceptions | ( | ) | [inline]
|
Definition at line 129 of file error.H.
References error::throwExceptions_.
Foam::OSstream & operator() | ( | const char * | functionName, |
const char * | sourceFileName, | ||
const int | sourceFileLineNumber = 0
|
||
) |
Convert to Ostream.
Prints basic message and then returns Ostream for further info.
Reimplemented from messageStream.
Foam::OSstream & operator() | ( | const string & | functionName, |
const char * | sourceFileName, | ||
const int | sourceFileLineNumber = 0
|
||
) |
Reimplemented from messageStream.
operator OSstream & | ( | ) |
Convert to Ostream.
Prints basic message and then returns Ostream for further info.
Reimplemented from messageStream.
Definition at line 131 of file error.C.
References Foam::abort(), Foam::endl(), and Foam::Perr.
Referenced by error::operator()().
OSstream& operator() | ( | ) | [inline]
|
Explicitly convert to Ostream for << operations.
Reimplemented from messageStream.
Definition at line 155 of file error.H.
References error::operator OSstream &().
Referenced by IOerror::operator()().
operator dictionary | ( | ) | const |
Create and return a dictionary.
Reimplemented in IOerror.
Definition at line 145 of file error.C.
References dictionary::add(), and string::replaceAll().
void printStack | ( | Foam::Ostream & | os ) | [static]
|
Helper function to print a stack.
Definition at line 36 of file dummyPrintStack.C.
void exit | ( | const int | errNo = 1
) |
Exit : can be called for any error to exit program. Prints stack.
before exiting.
Reimplemented in IOerror.
Definition at line 168 of file error.C.
References Foam::abort(), dictionary::add(), JobInfo::constructed, Foam::endl(), Foam::exit(), Pstream::exit(), JobInfo::exit(), Foam::jobInfo, Pstream::parRun(), and Foam::Perr.
Referenced by argList::argList(), error::error(), and Foam::exit().
void abort | ( | ) |
Abort : used to stop code for fatal errors. Prints stack before.
exiting.
Reimplemented in IOerror.
Definition at line 209 of file error.C.
References Pstream::abort(), Foam::abort(), JobInfo::abort(), dictionary::add(), JobInfo::constructed, Foam::endl(), Foam::jobInfo, Pstream::parRun(), and Foam::Perr.
Referenced by Foam::abort().
string functionName_ [protected]
|
Definition at line 77 of file error.H.
Referenced by error::functionName().
string sourceFileName_ [protected]
|
Definition at line 78 of file error.H.
Referenced by error::sourceFileName().
label sourceFileLineNumber_ [protected]
|
Definition at line 79 of file error.H.
Referenced by error::sourceFileLineNumber().
bool throwExceptions_ [protected]
|
Definition at line 83 of file error.H.
Referenced by error::dontThrowExceptions(), and error::throwExceptions().
OStringStream* messageStreamPtr_ [protected]
|
Definition at line 84 of file error.H.
Referenced by error::error().