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 &) | |
Construct from dictionary. More... | |
error (const error &) | |
Construct as copy. More... | |
virtual | ~error () throw () |
Destructor. More... | |
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 OSstream. More... | |
OSstream & | operator() (const string &functionName, const char *sourceFileName, const int sourceFileLineNumber=0) |
Convert to OSstream. More... | |
operator OSstream & () | |
Convert to OSstream. More... | |
OSstream & | operator() () |
Explicitly convert to OSstream for << operations. More... | |
operator dictionary () const | |
Create and return a dictionary. 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... | |
Static Public Member Functions | |
static void | safePrintStack (std::ostream &) |
Helper function to print a stack (if OpenFOAM IO not yet. More... | |
static void | printStack (Ostream &) |
Helper function to print a stack. More... | |
Protected Attributes | |
string | functionName_ |
string | sourceFileName_ |
label | sourceFileLineNumber_ |
bool | abort_ |
bool | throwExceptions_ |
OStringStream * | messageStreamPtr_ |
Friends | |
Ostream & | operator<< (Ostream &, const error &) |
Additional Inherited Members | |
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 which 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 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.
|
virtual |
Foam::string message | ( | ) | const |
Definition at line 162 of file error.C.
References error::messageStreamPtr_, and OStringStream::str().
Referenced by error::operator()(), and Foam::operator<<().
|
inline |
Definition at line 107 of file error.H.
References error::functionName_.
Referenced by error::dontThrowExceptions(), IOerror::ioEndLineNumber(), error::operator()(), IOerror::operator()(), and Foam::operator<<().
|
inline |
Definition at line 112 of file error.H.
References error::sourceFileName_.
Referenced by error::dontThrowExceptions(), IOerror::ioEndLineNumber(), error::operator()(), IOerror::operator()(), and Foam::operator<<().
|
inline |
Definition at line 117 of file error.H.
References error::sourceFileLineNumber_.
Referenced by error::dontThrowExceptions(), IOerror::ioEndLineNumber(), error::operator()(), IOerror::operator()(), and Foam::operator<<().
|
inline |
Definition at line 122 of file error.H.
Referenced by if(), and functionObjectList::read().
|
inline |
Definition at line 127 of file error.H.
References error::functionName(), error::sourceFileLineNumber(), and error::sourceFileName().
Referenced by functionObjectList::read().
Foam::OSstream & operator() | ( | const char * | functionName, |
const char * | sourceFileName, | ||
const int | sourceFileLineNumber = 0 |
||
) |
Convert to OSstream.
Prints basic message and returns OSstream for further info.
Definition at line 101 of file error.C.
References error::functionName(), error::functionName_, error::sourceFileLineNumber(), error::sourceFileLineNumber_, error::sourceFileName(), and error::sourceFileName_.
Foam::OSstream & operator() | ( | const string & | functionName, |
const char * | sourceFileName, | ||
const int | sourceFileLineNumber = 0 |
||
) |
Convert to OSstream.
Prints basic message and returns OSstream for further info.
Definition at line 116 of file error.C.
References error::abort(), dictionary::add(), Foam::endl(), error::functionName(), IOstream::good(), error::message(), error::messageStreamPtr_, Foam::Perr, string::replaceAll(), error::sourceFileLineNumber(), and error::sourceFileName().
operator OSstream & | ( | ) |
|
inline |
Explicitly convert to OSstream for << operations.
Definition at line 155 of file error.H.
References error::abort(), error::exit(), error::operator<<, error::printStack(), and error::safePrintStack().
Referenced by IOerror::operator()().
operator dictionary | ( | ) | const |
Create and return a dictionary.
|
static |
Helper function to print a stack (if OpenFOAM IO not yet.
initialised)
Definition at line 192 of file printStack.C.
References Foam::absolutePath(), Foam::demangleSymbol(), Foam::endl(), Foam::nl, Foam::printSourceFileAndLine(), and error::printStack().
Referenced by error::operator()().
|
static |
Helper function to print a stack.
Definition at line 30 of file dummyPrintStack.C.
Referenced by error::abort(), IOerror::abort(), Foam::chMod(), Foam::cp(), Foam::exists(), Foam::fileSize(), Foam::highResLastModified(), Foam::isDir(), Foam::isFile(), Foam::lastModified(), Foam::ln(), messageStream::masterStream(), Foam::mkDir(), Foam::mv(), Foam::mvBak(), error::operator()(), Foam::readDir(), Foam::reduce(), Foam::rm(), Foam::rmDir(), error::safePrintStack(), and Foam::type().
void exit | ( | const int | errNo = 1 | ) |
Exit : can be called for any error to exit program.
Prints stack before exiting.
Definition at line 168 of file error.C.
References error::abort(), error::abort_, dictionary::add(), JobInfo::constructed, Foam::endl(), JobInfo::exit(), UPstream::exit(), Foam::jobInfo, error::messageStreamPtr_, UPstream::parRun(), Foam::Perr, OStringStream::rewind(), and error::throwExceptions_.
Referenced by argList::argList(), error::error(), Foam::exit(), if(), IOerror::ioEndLineNumber(), error::operator()(), argList::parse(), argList::setOption(), and argList::unsetOption().
void abort | ( | ) |
Abort : used to stop code for fatal errors.
Prints stack before exiting.
Definition at line 209 of file error.C.
References JobInfo::abort(), UPstream::abort(), error::abort_, dictionary::add(), JobInfo::constructed, Foam::endl(), Foam::jobInfo, error::messageStreamPtr_, UPstream::parRun(), Foam::Perr, error::printStack(), OStringStream::rewind(), and error::throwExceptions_.
Referenced by Foam::abort(), error::exit(), IOerror::ioEndLineNumber(), and error::operator()().
Referenced by IOerror::ioEndLineNumber(), and error::operator()().
|
protected |
Definition at line 76 of file error.H.
Referenced by error::functionName(), and error::operator()().
|
protected |
Definition at line 77 of file error.H.
Referenced by error::operator()(), and error::sourceFileName().
|
protected |
Definition at line 78 of file error.H.
Referenced by error::operator()(), and error::sourceFileLineNumber().
|
protected |
Definition at line 80 of file error.H.
Referenced by error::abort(), IOerror::abort(), error::exit(), and IOerror::exit().
|
protected |
Definition at line 82 of file error.H.
Referenced by error::abort(), IOerror::abort(), error::exit(), and IOerror::exit().
|
protected |
Definition at line 83 of file error.H.
Referenced by error::abort(), IOerror::abort(), error::error(), error::exit(), IOerror::exit(), error::message(), error::operator()(), and error::~error().