Class to handle errors and exceptions in a simple, consistent stream-based manner. More...
Public Types | |
enum | handlerTypes : char { DEFAULT = 0, IGNORE, WARN, STRICT } |
Handling of errors. The exact handling depends on the local context. More... | |
Message type, error severity flags. More... |
Public Member Functions | |
error (const char *title) | |
Construct from title string. More... | |
error (const std::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 accumulated error messages. More... | |
const string & | functionName () const noexcept |
The currently defined function name for output messages. More... | |
const string & | sourceFileName () const noexcept |
The currently defined source-file name for output messages. More... | |
label | sourceFileLineNumber () const noexcept |
The currently defined source-file line number for output messages. More... | |
bool | throwing () const noexcept |
Return the current exception throwing state (on or off) More... | |
bool | throwing (const bool on) noexcept |
Specify exception throwing state (on or off) More... | |
OSstream & | stream () |
Return OSstream for output operations. More... | |
operator OSstream & () | |
Implicit cast to OSstream for << operations. More... | |
OSstream & | operator() () |
Explicit convert to OSstream for << operations. 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... | |
operator dictionary () const | |
Extract a dictionary representation of the error information. 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... | |
virtual void | write (Ostream &os, const bool withTitle=true) const |
Print error message. More... | |
bool | throwExceptions (const bool on=true) noexcept |
Specify exception throwing state (default is on) More... | |
bool | dontThrowExceptions () noexcept |
Deactivate exception throwing. More... | |
Static Public Member Functions | |
static bool | master (const label communicator=-1) |
Like Pstream::master but with a Pstream::parRun guard in case Pstream has not yet been initialised. More... | |
static bool | warnAboutAge (const int version) noexcept |
Test if an age warning should be emitted. More... | |
static bool | warnAboutAge (const char *what, const int version) |
Emit warning on stderr about something being old. More... | |
static void | safePrintStack (std::ostream &os, int size=-1) |
Helper function to print a stack, with optional upper limit. Used when OpenFOAM IO not yet initialised. More... | |
static void | printStack (Ostream &os, int size=-1) |
Helper function to print a stack, with optional upper limit. More... | |
static bool | useAbort () |
True if FOAM_ABORT is on. More... | |
Static Public Attributes | |
static const Enum< handlerTypes > | handlerNames |
Names of the error handler types. More... | |
Protected Member Functions | |
void | simpleExit (const int errNo, const bool isAbort) |
Exit or abort, without throwing or job control handling. More... | |
Protected Attributes | |
string | functionName_ |
string | sourceFileName_ |
label | sourceFileLineNumber_ |
bool | throwing_ |
std::unique_ptr< OStringStream > | messageStreamPtr_ |
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).
|
strong |
|
explicit |
|
inlineexplicit |
|
explicit |
|
protected |
Exit or abort, without throwing or job control handling.
Definition at line 270 of file error.C.
References Foam::abort(), UPstream::abort(), Foam::endl(), Foam::exit(), UPstream::exit(), Foam::nl, UPstream::parRun(), Foam::Perr, error::printStack(), and error::useAbort().
|
static |
Like Pstream::master but with a Pstream::parRun guard in case Pstream has not yet been initialised.
communicator | is the numbered MPI communicator. By default it uses UPstream::worldComm |
Definition at line 53 of file error.C.
References UPstream::master(), and UPstream::parRun().
Referenced by Foam::expandLeadingTilde(), and Foam::warnCompatDegrees().
|
staticnoexcept |
Test if an age warning should be emitted.
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 67 of file error.C.
References Foam::foamVersion::api, and Foam::foamVersion::version.
Referenced by Foam::expandLeadingTilde(), and timeControl::read().
|
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 74 of file error.C.
References Foam::foamVersion::api, Foam::endl(), and Foam::foamVersion::version.
Foam::string message | ( | ) | const |
The accumulated error message.
Definition at line 339 of file error.C.
Referenced by motionSmootherAlgo::checkMesh().
void clear | ( | ) | const |
Clear any accumulated error messages.
Definition at line 350 of file error.C.
Referenced by motionSmootherAlgo::checkMesh().
|
inlinenoexcept |
The currently defined function name for output messages.
Definition at line 199 of file error.H.
References error::functionName_.
|
inlinenoexcept |
The currently defined source-file name for output messages.
Definition at line 207 of file error.H.
References error::sourceFileName_.
|
inlinenoexcept |
The currently defined source-file line number for output messages.
Definition at line 215 of file error.H.
References error::sourceFileLineNumber_.
|
inlinenoexcept |
Return the current exception throwing state (on or off)
Definition at line 223 of file error.H.
References error::throwing_.
Referenced by functionObjectList::end(), functionObjectList::execute(), if(), IOobjectList::IOobjectList(), functionObjectList::read(), and error::throwExceptions().
|
inlinenoexcept |
Specify exception throwing state (on or off)
Definition at line 233 of file error.H.
References error::throwing_.
Foam::OSstream & stream | ( | ) |
Return OSstream for output operations.
Definition at line 321 of file error.C.
References Foam::abort(), Foam::endl(), Foam::nl, and Foam::Perr.
Referenced by error::operator OSstream &(), error::operator()(), and Time::readDict().
|
inline |
Implicit cast to OSstream for << operations.
Definition at line 251 of file error.H.
References error::stream().
|
inline |
Explicit convert to OSstream for << operations.
Definition at line 259 of file error.H.
References error::stream().
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 |
||
) |
operator dictionary | ( | ) | const |
Extract a dictionary representation of the error information.
|
static |
Helper function to print a stack, with optional upper limit. Used when OpenFOAM IO not yet initialised.
Definition at line 26 of file dummyPrintStack.C.
|
static |
Helper function to print a stack, with optional upper limit.
Definition at line 27 of file dummyPrintStack.C.
Referenced by Foam::exitNow(), messageStream::masterStream(), Foam::reduce(), error::simpleExit(), and UPstream_mpi_receive().
|
static |
True if FOAM_ABORT is on.
Definition at line 110 of file error.C.
References Switch::find(), and Foam::getEnv().
Referenced by Foam::exitNow(), and error::simpleExit().
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 359 of file error.C.
Referenced by Foam::exit(), and if().
void abort | ( | ) |
Abort : used to stop code for fatal errors.
Prints stack before exiting.
Definition at line 365 of file error.C.
Referenced by Foam::abort().
|
virtual |
Print error message.
Reimplemented in IOerror.
Definition at line 371 of file error.C.
References Foam::foamVersion::api, IOstream::bad(), messageStream::level, Foam::nl, os(), Foam::foamVersion::patch, and Foam::foamVersion::patched().
Referenced by functionObjectList::end(), functionObjectList::execute(), Foam::operator<<(), argList::parse(), and functionObjectList::read().
|
inlinenoexcept |
Specify exception throwing state (default is on)
Definition at line 351 of file error.H.
References error::throwing().
Referenced by error::dontThrowExceptions().
|
inlinenoexcept |
Deactivate exception throwing.
Definition at line 361 of file error.H.
References error::throwExceptions().
|
protected |
Definition at line 87 of file error.H.
Referenced by error::functionName().
|
protected |
Definition at line 88 of file error.H.
Referenced by error::sourceFileName().
|
protected |
Definition at line 89 of file error.H.
Referenced by error::sourceFileLineNumber().
|
protected |
Definition at line 90 of file error.H.
Referenced by error::throwing().
|
protected |
Definition at line 91 of file error.H.
Referenced by error::error().
|
static |
Names of the error handler types.
Definition at line 120 of file error.H.
Referenced by surfaceFieldValue::read().