Public Member Functions | Static Public Member Functions | Protected Attributes | Friends | List of all members
error Class Reference

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

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

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 stringfunctionName () const
 
const stringsourceFileName () const
 
label sourceFileLineNumber () const
 
void throwExceptions ()
 
void dontThrowExceptions ()
 
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. 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...
 
- Public Member Functions inherited from messageStream
 messageStream (const string &title, errorSeverity, const int maxErrors=0)
 Construct from components. More...
 
 messageStream (const dictionary &)
 Construct from dictionary. 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 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_
 
OStringStreammessageStreamPtr_
 
- Protected Attributes inherited from messageStream
string title_
 
errorSeverity severity_
 
int maxErrors_
 
int errorCount_
 

Friends

Ostreamoperator<< (Ostream &, const error &)
 

Additional Inherited Members

- Public Types inherited from messageStream
enum  errorSeverity { INFO, WARNING, SERIOUS, FATAL }
 Severity flags. More...
 
- Static Public Attributes inherited from messageStream
static int level
 

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 which 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 66 of file error.H.

Constructor & Destructor Documentation

◆ error() [1/3]

error ( const string title)

Construct from title string.

Definition at line 36 of file error.C.

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

Here is the call graph for this function:

◆ error() [2/3]

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.

Here is the call graph for this function:

◆ error() [3/3]

error ( const error err)

Construct as copy.

Definition at line 79 of file error.C.

◆ ~error()

~error ( )
throw (
)
virtual

Destructor.

Definition at line 94 of file error.C.

References error::messageStreamPtr_.

Member Function Documentation

◆ message()

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

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

◆ functionName()

const string& functionName ( ) const
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<<().

Here is the caller graph for this function:

◆ sourceFileName()

const string& sourceFileName ( ) const
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<<().

Here is the caller graph for this function:

◆ sourceFileLineNumber()

label sourceFileLineNumber ( ) const
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<<().

Here is the caller graph for this function:

◆ throwExceptions()

void throwExceptions ( )
inline

Definition at line 122 of file error.H.

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

Here is the caller graph for this function:

◆ dontThrowExceptions()

void dontThrowExceptions ( )
inline

Definition at line 127 of file error.H.

References error::functionName(), error::sourceFileLineNumber(), and error::sourceFileName().

Referenced by functionObjectList::read().

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

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

References error::functionName(), error::functionName_, error::sourceFileLineNumber(), error::sourceFileLineNumber_, error::sourceFileName(), and error::sourceFileName_.

Here is the call graph for this function:

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

Here is the call graph for this function:

◆ 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 155 of file error.H.

References error::abort(), error::exit(), error::operator<<, error::printStack(), and error::safePrintStack().

Referenced by IOerror::operator()().

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

◆ operator dictionary()

operator dictionary ( ) const

Create and return a dictionary.

◆ safePrintStack()

void safePrintStack ( std::ostream &  os)
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()().

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

◆ printStack()

void printStack ( Ostream os)
static

◆ exit()

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

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

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

Friends And Related Function Documentation

◆ operator<<

Ostream& operator<< ( Ostream ,
const error  
)
friend

Member Data Documentation

◆ functionName_

string functionName_
protected

Definition at line 76 of file error.H.

Referenced by error::functionName(), and error::operator()().

◆ sourceFileName_

string sourceFileName_
protected

Definition at line 77 of file error.H.

Referenced by error::operator()(), and error::sourceFileName().

◆ sourceFileLineNumber_

label sourceFileLineNumber_
protected

Definition at line 78 of file error.H.

Referenced by error::operator()(), and error::sourceFileLineNumber().

◆ abort_

bool abort_
protected

Definition at line 80 of file error.H.

Referenced by error::abort(), IOerror::abort(), error::exit(), and IOerror::exit().

◆ throwExceptions_

bool throwExceptions_
protected

Definition at line 82 of file error.H.

Referenced by error::abort(), IOerror::abort(), error::exit(), and IOerror::exit().

◆ messageStreamPtr_

OStringStream* messageStreamPtr_
protected

The documentation for this class was generated from the following files: