error Class Reference

Class to handle errors and exceptions in a simple, consistent stream-based manner. More...

Inheritance diagram for error:
[legend]
Collaboration diagram for error:
[legend]

Public Member Functions

 error (const string &title)
 Construct from title string. More...
 
 error (const dictionary &errDict)
 Construct from dictionary. More...
 
 error (const error &err)
 Construct as copy. More...
 
virtual ~error () throw ()
 Destructor. More...
 
string message () const
 
void clear () const
 Clear any messages. More...
 
const stringfunctionName () const
 
const stringsourceFileName () const
 
label sourceFileLineNumber () const
 
bool throwing () const
 Return the current exception throwing (on or off) More...
 
bool throwExceptions (bool doThrow)
 Activate/deactivate exception throwing. More...
 
bool throwExceptions ()
 Activate exception throwing. More...
 
bool dontThrowExceptions ()
 Deactivate exception throwing. More...
 
OSstreamoperator() (const char *functionName, const char *sourceFileName, const int sourceFileLineNumber=0)
 Convert to OSstream. More...
 
OSstreamoperator() (const string &functionName, const char *sourceFileName, const int sourceFileLineNumber=0)
 Convert to OSstream. More...
 
 operator OSstream & ()
 Convert to OSstream. More...
 
OSstreamoperator() ()
 Explicitly convert to OSstream for << operations. More...
 
 operator dictionary () const
 Create and return a dictionary representation of the error. 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...
 
void write (Ostream &os, const bool includeTitle=true) const
 Print error message. More...
 
- Public Member Functions inherited from messageStream
 messageStream (const string &title, const errorSeverity severity, const int maxErrors=0)
 Construct from components. More...
 
 messageStream (const dictionary &dict)
 Construct as Fatal from dictionary, extracting the 'title'. More...
 
const stringtitle () const
 Return the title of this error type. More...
 
int maxErrors () const
 Return the maximum number of errors before program termination. More...
 
int & maxErrors ()
 Return non-const access to the maximum number of errors before. More...
 
OSstreammasterStream (const label communicator)
 Convert to OSstream. More...
 
OSstreamoperator() (const char *functionName, const char *sourceFileName, const int sourceFileLineNumber=0)
 Convert to OSstream. More...
 
OSstreamoperator() (const string &functionName, const char *sourceFileName, const int sourceFileLineNumber=0)
 Convert to OSstream. More...
 
OSstreamoperator() (const char *functionName, const char *sourceFileName, const int sourceFileLineNumber, const string &ioFileName, const label ioStartLineNumber=-1, const label ioEndLineNumber=-1)
 Convert to OSstream. More...
 
OSstreamoperator() (const char *functionName, const char *sourceFileName, const int sourceFileLineNumber, const IOstream &)
 Convert to OSstream. More...
 
OSstreamoperator() (const char *functionName, const char *sourceFileName, const int sourceFileLineNumber, const dictionary &)
 Convert to OSstream. More...
 
 operator OSstream & ()
 Convert to OSstream for << operations. More...
 
OSstreamoperator() ()
 Explicitly convert to OSstream for << operations. More...
 

Static Public Member Functions

static void warnAboutAge (const char *what, const int version)
 Emit warning on stderr about something being old. More...
 
static void safePrintStack (std::ostream &os)
 
static void printStack (Ostream &os)
 Helper function to print a stack. More...
 

Protected Attributes

string functionName_
 
string sourceFileName_
 
label sourceFileLineNumber_
 
bool throwExceptions_
 
OStringStreammessageStreamPtr_
 
- Protected Attributes inherited from messageStream
string title_
 
errorSeverity severity_
 
int maxErrors_
 
int errorCount_
 

Additional Inherited Members

- Public Types inherited from messageStream
enum  errorSeverity {
  INFO = 1, WARNING, SERIOUS, FATAL,
  INFO_STDERR = INFO | 0x10
}
 Message type, or error severity flags. More...
 
- Static Public Attributes inherited from messageStream
static int level
 Controls the output verbosity of messageStream. More...
 

Detailed Description

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).

Usage
error << "message1" << "message2" << FoamDataType << exit(errNo);
error << "message1" << "message2" << FoamDataType << abort();
Source files

Definition at line 64 of file error.H.

Constructor & Destructor Documentation

◆ error() [1/3]

error ( const string title)
explicit

Construct from title string.

Definition at line 75 of file error.C.

References Foam::endl(), error::exit(), IOstream::good(), error::messageStreamPtr_, Foam::nl, and Foam::Perr.

Here is the call graph for this function:

◆ error() [2/3]

error ( const dictionary errDict)
explicit

Construct from dictionary.

Definition at line 95 of file error.C.

References Foam::endl(), error::exit(), IOstream::good(), error::messageStreamPtr_, Foam::nl, and Foam::Perr.

Here is the call graph for this function:

◆ error() [3/3]

error ( const error err)

Construct as copy.

Definition at line 116 of file error.C.

◆ ~error()

~error ( )
throw (
)
virtual

Destructor.

Definition at line 132 of file error.C.

Member Function Documentation

◆ warnAboutAge()

void warnAboutAge ( const char *  what,
const int  version 
)
static

Emit warning on stderr about something being old.

Parameters
whatdescription for the warning
versionis 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 40 of file error.C.

References Foam::foamVersion::api, Foam::endl(), and Foam::foamVersion::version.

Referenced by Foam::expandLeadingTilde(), and timeControl::read().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ message()

Foam::string message ( ) const

Definition at line 204 of file error.C.

Referenced by snappyLayerDriver::addLayers(), and motionSmootherAlgo::checkMesh().

Here is the caller graph for this function:

◆ clear()

void clear ( ) const

Clear any messages.

Definition at line 210 of file error.C.

Referenced by motionSmootherAlgo::checkMesh().

Here is the caller graph for this function:

◆ functionName()

const string& functionName ( ) const
inline

Definition at line 117 of file error.H.

References error::functionName_.

◆ sourceFileName()

const string& sourceFileName ( ) const
inline

Definition at line 122 of file error.H.

References error::sourceFileName_.

◆ sourceFileLineNumber()

label sourceFileLineNumber ( ) const
inline

Definition at line 127 of file error.H.

References error::sourceFileLineNumber_.

◆ throwing()

bool throwing ( ) const
inline

Return the current exception throwing (on or off)

Definition at line 133 of file error.H.

References error::throwExceptions_.

◆ throwExceptions() [1/2]

bool throwExceptions ( bool  doThrow)
inline

Activate/deactivate exception throwing.

Returns
the previous throwing state

Definition at line 140 of file error.H.

Referenced by if(), IOobjectList::IOobjectList(), and functionObjectList::read().

Here is the caller graph for this function:

◆ throwExceptions() [2/2]

bool throwExceptions ( )
inline

Activate exception throwing.

Returns
the previous throwing state

Definition at line 149 of file error.H.

◆ dontThrowExceptions()

bool dontThrowExceptions ( )
inline

Deactivate exception throwing.

Returns
the previous throwing state

Definition at line 156 of file error.H.

◆ operator()() [1/3]

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 141 of file error.C.

◆ operator()() [2/3]

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 156 of file error.C.

◆ operator OSstream &()

operator OSstream & ( )

Convert to OSstream.

Prints basic message and returns OSstream for further info.

◆ operator()() [3/3]

OSstream& operator() ( )
inline

Explicitly convert to OSstream for << operations.

Definition at line 184 of file error.H.

Referenced by IOerror::operator()().

Here is the caller graph for this function:

◆ operator dictionary()

operator dictionary ( ) const

Create and return a dictionary representation of the error.

◆ safePrintStack()

void safePrintStack ( std::ostream &  os)
static

Helper function to print a stack, used when OpenFOAM IO not yet initialised.

Definition at line 32 of file dummyPrintStack.C.

◆ printStack()

void printStack ( Ostream os)
static

Helper function to print a stack.

Definition at line 36 of file dummyPrintStack.C.

Referenced by messageStream::masterStream(), and Foam::reduce().

Here is the caller graph for this function:

◆ exit()

void exit ( const int  errNo = 1)

Exit : can be called for any error to exit program.

Prints stack before exiting, when FOAM_ABORT is on.

Definition at line 216 of file error.C.

References Foam::abort(), dictionary::add(), JobInfo::constructed, Foam::endl(), Foam::env(), JobInfo::exit(), Foam::exit(), UPstream::exit(), Foam::jobInfo, Foam::nl, UPstream::parRun(), and Foam::Perr.

Referenced by error::error(), Foam::exit(), and if().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ abort()

void abort ( )

Abort : used to stop code for fatal errors.

Prints stack before exiting.

Definition at line 253 of file error.C.

References JobInfo::abort(), Foam::abort(), UPstream::abort(), dictionary::add(), JobInfo::constructed, Foam::endl(), Foam::env(), Foam::exit(), Foam::jobInfo, Foam::nl, UPstream::parRun(), and Foam::Perr.

Referenced by Foam::abort().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ write()

void write ( Ostream os,
const bool  includeTitle = true 
) const

Print error message.

Definition at line 300 of file error.C.

References messageStream::level, and Foam::nl.

Referenced by Foam::operator<<(), argList::parse(), and functionObjectList::read().

Here is the caller graph for this function:

Member Data Documentation

◆ functionName_

string functionName_
protected

Definition at line 74 of file error.H.

Referenced by error::functionName().

◆ sourceFileName_

string sourceFileName_
protected

Definition at line 75 of file error.H.

Referenced by error::sourceFileName().

◆ sourceFileLineNumber_

label sourceFileLineNumber_
protected

Definition at line 76 of file error.H.

Referenced by error::sourceFileLineNumber().

◆ throwExceptions_

bool throwExceptions_
protected

Definition at line 78 of file error.H.

Referenced by error::throwing().

◆ messageStreamPtr_

OStringStream* messageStreamPtr_
protected

Definition at line 79 of file error.H.

Referenced by error::error().


The documentation for this class was generated from the following files:
Foam::error::error
error(const string &title)
Construct from title string.
Definition: error.C:75
Foam::error::exit
void exit(const int errNo=1)
Exit : can be called for any error to exit program.
Definition: error.C:216
Foam::error::abort
void abort()
Abort : used to stop code for fatal errors.
Definition: error.C:253