Class to handle errors and exceptions in a simple, consistent stream-based manner. More...
#include <error.H>


Public Types | |
| enum class | 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. | |
| error (const std::string &title) | |
| Construct from title string. | |
| error (const dictionary &errDict) | |
| Construct from dictionary. | |
| error (const error &err) | |
| Copy construct. | |
| virtual | ~error () noexcept |
| Destructor. | |
| string | message () const |
| The accumulated error message. | |
| void | clear () const |
| Clear any accumulated error messages. | |
| const string & | functionName () const noexcept |
| The currently defined function name for output messages. | |
| const string & | sourceFileName () const noexcept |
| The currently defined source-file name for output messages. | |
| int | sourceFileLineNumber () const noexcept |
| The currently defined source-file line number for output messages. | |
| bool | throwing () const noexcept |
| Return the current exception throwing state (on or off). | |
| bool | throwing (const bool on) noexcept |
| Specify exception throwing state (on or off). | |
| OSstream & | stream () |
| Return OSstream for output operations. | |
| operator OSstream & () | |
| Implicit cast to OSstream for << operations. | |
| OSstream & | operator() () |
| Explicit convert to OSstream for << operations. | |
| OSstream & | operator() (string functionName, const char *sourceFileName=nullptr, const int sourceFileLineNumber=-1) |
| Define basic print message with originating function name, optionally with 'source file, line number'. | |
| OSstream & | operator() (const char *functionName, const char *sourceFileName=nullptr, const int sourceFileLineNumber=-1) |
| Define basic print message with originating function name, optionally with 'source file, line number'. | |
| operator dictionary () const | |
| Extract a dictionary representation of the error information. | |
| void | exit (const int errNo=1) |
| Exit : can be called for any error to exit program. | |
| void | abort () |
| Abort : used to stop code for fatal errors. | |
| virtual void | write (Ostream &os, const bool withTitle=true) const |
| Print error message. | |
| bool | throwExceptions (const bool on=true) noexcept |
| Specify exception throwing state (default is on). | |
| bool | dontThrowExceptions () noexcept |
| Deactivate exception throwing. | |
Static Public Member Functions | |
| static bool | master (const int communicator=-1) |
| Like Pstream::master but with a Pstream::parRun guard in case Pstream has not yet been initialised. | |
| static bool | warnAboutAge (const int version) noexcept |
| Test if an age warning should be emitted. | |
| static bool | warnAboutAge (const char *what, const int version) |
| Emit warning on stderr about something being old. | |
| 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. | |
| static void | printStack (Ostream &os, int size=-1) |
| Helper function to print a stack, with optional upper limit. | |
| static bool | useAbort () |
| True if FOAM_ABORT is on. | |
Static Public Attributes | |
| static const Enum< handlerTypes > | handlerNames |
| Names of the error handler types. | |
Protected Member Functions | |
| void | simpleExit (const int errNo, const bool isAbort) |
| Exit or abort, without throwing or job control handling. | |
Protected Attributes | |
| string | functionName_ |
| string | sourceFileName_ |
| int | 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 |
Construct from title string.
Definition at line 119 of file error.C.
References messageStream::FATAL, functionName_, messageStream::messageStream(), messageStreamPtr_, sourceFileLineNumber_, sourceFileName_, throwing_, and messageStream::title().
Referenced by error(), error(), IOerror::IOerror(), and IOerror::IOerror().


|
inlineexplicit |
Construct from title string.
Definition at line 133 of file error.H.
References error(), and messageStream::title().

|
explicit |
Construct from dictionary.
Definition at line 131 of file error.C.
References functionName_, messageStream::messageStream(), messageStreamPtr_, sourceFileLineNumber_, sourceFileName_, and throwing_.

| error | ( | const error & | err | ) |
Copy construct.
Definition at line 143 of file error.C.
References error(), functionName_, messageStream::messageStream(), messageStreamPtr_, sourceFileLineNumber_, sourceFileName_, and throwing_.

|
virtualnoexcept |
|
protected |
Exit or abort, without throwing or job control handling.
Definition at line 263 of file error.C.
References UPstream::abort(), Foam::endl(), UPstream::exit(), Foam::nl, UPstream::parRun(), Foam::Perr, printStack(), and 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 dictionary::csearchCompat(), Foam::warnCompatDegrees(), and FieldBase::warnLocalBoundaryConsistencyCompat().


|
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.
Referenced by dictionary::csearchCompat(), timeControl::read(), and FieldBase::warnLocalBoundaryConsistencyCompat().

|
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::string message | ( | ) | const |
The accumulated error message.
Definition at line 332 of file error.C.
References messageStreamPtr_.
Referenced by write(), and IOerror::write().

| void clear | ( | ) | const |
Clear any accumulated error messages.
Definition at line 343 of file error.C.
References messageStreamPtr_.
|
inlinenoexcept |
The currently defined function name for output messages.
Definition at line 199 of file error.H.
References functionName(), functionName_, and Foam::noexcept.
Referenced by functionName(), operator()(), operator()(), IOerror::operator()(), IOerror::operator()(), IOerror::operator()(), IOerror::SafeFatalIOError(), write(), and IOerror::write().


|
inlinenoexcept |
The currently defined source-file name for output messages.
Definition at line 207 of file error.H.
References Foam::noexcept, and sourceFileName_.
Referenced by operator()(), operator()(), IOerror::operator()(), IOerror::operator()(), IOerror::operator()(), IOerror::SafeFatalIOError(), write(), and IOerror::write().

|
inlinenoexcept |
The currently defined source-file line number for output messages.
Definition at line 215 of file error.H.
References Foam::noexcept, and sourceFileLineNumber_.
Referenced by operator()(), operator()(), IOerror::operator()(), IOerror::operator()(), IOerror::operator()(), IOerror::SafeFatalIOError(), write(), and IOerror::write().

|
inlinenoexcept |
Return the current exception throwing state (on or off).
Definition at line 223 of file error.H.
References Foam::noexcept, and throwing_.
Referenced by throwExceptions().

|
inlinenoexcept |
| Foam::OSstream & stream | ( | ) |
Return OSstream for output operations.
Definition at line 314 of file error.C.
References Foam::abort(), Foam::endl(), messageStreamPtr_, Foam::nl, and Foam::Perr.
Referenced by operator OSstream &(), operator()(), operator()(), and operator()().


|
inline |
|
inline |
| Foam::OSstream & operator() | ( | string | functionName, |
| const char * | sourceFileName = nullptr, | ||
| const int | sourceFileLineNumber = -1 ) |
Define basic print message with originating function name, optionally with 'source file, line number'.
Definition at line 171 of file error.C.
References functionName(), functionName_, sourceFileLineNumber(), sourceFileLineNumber_, sourceFileName(), sourceFileName_, and stream().

| Foam::OSstream & operator() | ( | const char * | functionName, |
| const char * | sourceFileName = nullptr, | ||
| const int | sourceFileLineNumber = -1 ) |
Define basic print message with originating function name, optionally with 'source file, line number'.
Definition at line 192 of file error.C.
References functionName(), functionName_, sourceFileLineNumber(), sourceFileLineNumber_, sourceFileName(), sourceFileName_, and stream().

| operator dictionary | ( | ) | const |
Extract a dictionary representation of the error information.
References os().

|
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.
References os().

|
static |
Helper function to print a stack, with optional upper limit.
Definition at line 27 of file dummyPrintStack.C.
References os().
Referenced by Foam::chMod(), Foam::cp(), Foam::exists(), Foam::exitNow(), Foam::fileSize(), Foam::highResLastModified(), Foam::isDir(), Foam::isFile(), Foam::lastModified(), Foam::ln(), messageStream::masterStream(), Foam::mkDir(), Foam::mode(), Foam::mv(), Foam::mvBak(), GeometricField< Type, PatchField, GeoMesh >::oldTime(), Foam::readDir(), Foam::readLink(), Foam::reduce(), Foam::rm(), Foam::rmDir(), and simpleExit().


|
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 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 352 of file error.C.
Referenced by Foam::exit().

| void abort | ( | ) |
Abort : used to stop code for fatal errors.
Prints stack before exiting.
Definition at line 358 of file error.C.
Referenced by Foam::abort().

|
virtual |
Print error message.
Reimplemented in IOerror.
Definition at line 364 of file error.C.
References Foam::foamVersion::api, functionName(), messageStream::level, message(), Foam::nl, os(), Foam::foamVersion::patch, Foam::foamVersion::patched(), sourceFileLineNumber(), sourceFileName(), and messageStream::title().
Referenced by functionObjectList::end(), functionObjectList::execute(), Foam::operator<<(), and functionObjectList::read().


|
inlinenoexcept |
Specify exception throwing state (default is on).
Definition at line 343 of file error.H.
References Foam::noexcept, and throwing().
Referenced by dontThrowExceptions().


|
inlinenoexcept |
Deactivate exception throwing.
Definition at line 353 of file error.H.
References Foam::noexcept, and throwExceptions().

|
protected |
Definition at line 87 of file error.H.
Referenced by error(), error(), error(), functionName(), operator()(), and operator()().
|
protected |
Definition at line 88 of file error.H.
Referenced by error(), error(), error(), operator()(), operator()(), and sourceFileName().
|
protected |
Definition at line 89 of file error.H.
Referenced by error(), error(), error(), operator()(), operator()(), and sourceFileLineNumber().
|
protected |
Definition at line 90 of file error.H.
Referenced by error(), error(), error(), throwing(), and throwing().
|
protected |
|
static |