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... | |
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... | |
OSstream & | operator() () |
Explicitly convert to OSstream for << operations. More... | |
operator OSstream & () | |
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 | messageStream_ |
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::messageStream_, and Foam::Perr.
Foam::string message | ( | ) | const |
Definition at line 119 of file error.C.
References error::messageStream_, and OStringStream::str().
Referenced by error::operator()(), and Foam::operator<<().
|
inline |
Definition at line 100 of file error.H.
References error::functionName_.
Referenced by error::dontThrowExceptions(), IOerror::ioEndLineNumber(), error::operator()(), IOerror::operator()(), and Foam::operator<<().
|
inline |
Definition at line 105 of file error.H.
References error::sourceFileName_.
Referenced by error::dontThrowExceptions(), IOerror::ioEndLineNumber(), error::operator()(), IOerror::operator()(), and Foam::operator<<().
|
inline |
Definition at line 110 of file error.H.
References error::sourceFileLineNumber_.
Referenced by error::dontThrowExceptions(), IOerror::ioEndLineNumber(), error::operator()(), IOerror::operator()(), and Foam::operator<<().
|
inline |
|
inline |
Definition at line 120 of file error.H.
References error::functionName(), error::operator()(), error::sourceFileLineNumber(), and error::sourceFileName().
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 58 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 73 of file error.C.
References error::sourceFileLineNumber(), and error::sourceFileName().
Foam::OSstream & operator() | ( | ) |
Explicitly convert to OSstream for << operations.
Definition at line 88 of file error.C.
References error::abort(), dictionary::add(), Foam::endl(), error::functionName(), IOstream::good(), error::message(), error::messageStream_, Foam::Perr, string::replaceAll(), error::sourceFileLineNumber(), and error::sourceFileName().
Referenced by error::dontThrowExceptions(), error::operator OSstream &(), and IOerror::operator()().
|
inline |
Convert to OSstream for << operations.
Definition at line 147 of file error.H.
References error::abort(), error::exit(), error::operator()(), error::operator<<, error::printStack(), and error::safePrintStack().
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 OSstream &().
|
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(), Foam::mkDir(), Foam::mode(), Foam::mv(), Foam::mvBak(), error::operator OSstream &(), messageStream::operator()(), Foam::readDir(), Foam::reduce(), Foam::rm(), Foam::rmDir(), error::safePrintStack(), and pointMesh::~pointMesh().
void exit | ( | const int | errNo = 1 | ) |
Exit : can be called for any error to exit program.
Prints stack before exiting.
Definition at line 125 of file error.C.
References error::abort(), error::abort_, dictionary::add(), jobInfo::constructed, Foam::endl(), jobInfo::exit(), UPstream::exit(), Foam::jobInfo_, error::messageStream_, UPstream::parRun(), Foam::Perr, OStringStream::rewind(), and error::throwExceptions_.
Referenced by argList::argList(), error::error(), Foam::exit(), if(), IOerror::ioEndLineNumber(), error::operator OSstream &(), argList::parse(), argList::setOption(), and argList::unsetOption().
void abort | ( | ) |
Abort : used to stop code for fatal errors.
Prints stack before exiting.
Definition at line 166 of file error.C.
References jobInfo::abort(), UPstream::abort(), error::abort_, dictionary::add(), jobInfo::constructed, Foam::endl(), Foam::jobInfo_, error::messageStream_, UPstream::parRun(), Foam::Perr, error::printStack(), OStringStream::rewind(), and error::throwExceptions_.
Referenced by Foam::abort(), error::exit(), IOerror::ioEndLineNumber(), error::operator OSstream &(), and error::operator()().
Referenced by IOerror::ioEndLineNumber(), and error::operator OSstream &().
|
protected |
Definition at line 77 of file error.H.
Referenced by error::functionName(), and error::operator()().
|
protected |
Definition at line 78 of file error.H.
Referenced by error::operator()(), and error::sourceFileName().
|
protected |
Definition at line 79 of file error.H.
Referenced by error::operator()(), and error::sourceFileLineNumber().
|
protected |
Definition at line 81 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::exit(), and IOerror::exit().
|
protected |
Definition at line 85 of file error.H.
Referenced by error::abort(), IOerror::abort(), error::error(), error::exit(), IOerror::exit(), error::message(), and error::operator()().