FreeFOAM The Cross-Platform CFD Toolkit
error Class Reference

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

#include <OpenFOAM/error.H>


Detailed Description

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

The error class is globaly 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 of if the exception handling has beed switched on (off by default).

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

Definition at line 67 of file error.H.

+ Inheritance diagram for error:
+ Collaboration diagram for error:

List of all members.

Public Member Functions

 error (const string &title)
 Construct from title string.
 error (const dictionary &errDict)
 Construct from dictionary.
 error (const error &err)
 Construct as copy.
virtual ~error () throw ()
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 Ostream.
OSstreamoperator() (const string &functionName, const char *sourceFileName, const int sourceFileLineNumber=0)
 operator OSstream & ()
 Convert to Ostream.
OSstreamoperator() ()
 Explicitly convert to Ostream for << operations.
 operator dictionary () const
 Create and return a dictionary.
void exit (const int errNo=1)
 Exit : can be called for any error to exit program. Prints stack.
void abort ()
 Abort : used to stop code for fatal errors. Prints stack before.
- Public Member Functions inherited from messageStream
 messageStream (const string &title, errorSeverity sev, const int maxErrors=0)
 Construct from components.
 messageStream (const dictionary &dict)
 Construct from dictionary.
const stringtitle () const
 Return the title of this error type.
int maxErrors () const
 Return the maximum number of errors before program termination.
int & maxErrors ()
 Return non-const access to the maximum number of errors before.
OSstreamoperator() (const char *functionName, const char *sourceFileName, const int sourceFileLineNumber, const string &ioFileName, const label ioStartLineNumber=-1, const label ioEndLineNumber=-1)
 Convert to Ostream.
OSstreamoperator() (const char *functionName, const char *sourceFileName, const int sourceFileLineNumber, const IOstream &)
 Convert to Ostream.
OSstreamoperator() (const char *functionName, const char *sourceFileName, const int sourceFileLineNumber, const dictionary &)
 Convert to Ostream.

Static Public Member Functions

static void printStack (Ostream &os)
 Helper function to print a stack.

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

Constructor & Destructor Documentation

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.

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.

error ( const error err)

Construct as copy.

Definition at line 79 of file error.C.

~error ( ) throw ()
virtual

Definition at line 94 of file error.C.


Member Function Documentation

Foam::string message ( ) const

Definition at line 162 of file error.C.

Referenced by Foam::operator<<().

const string& functionName ( ) const
inline

Definition at line 109 of file error.H.

References error::functionName_.

Referenced by Foam::operator<<().

const string& sourceFileName ( ) const
inline

Definition at line 114 of file error.H.

References error::sourceFileName_.

Referenced by Foam::operator<<().

label sourceFileLineNumber ( ) const
inline

Definition at line 119 of file error.H.

References error::sourceFileLineNumber_.

Referenced by Foam::operator<<().

void throwExceptions ( )
inline
void dontThrowExceptions ( )
inline

Definition at line 129 of file error.H.

References error::throwExceptions_.

Foam::OSstream & operator() ( const char *  functionName,
const char *  sourceFileName,
const int  sourceFileLineNumber = 0 
)

Convert to Ostream.

Prints basic message and then returns Ostream for further info.

Reimplemented from messageStream.

Definition at line 101 of file error.C.

Foam::OSstream & operator() ( const string functionName,
const char *  sourceFileName,
const int  sourceFileLineNumber = 0 
)

Reimplemented from messageStream.

Definition at line 116 of file error.C.

operator OSstream & ( )

Convert to Ostream.

Prints basic message and then returns Ostream for further info.

Reimplemented from messageStream.

Definition at line 131 of file error.C.

References Foam::abort(), Foam::endl(), and Foam::Perr.

OSstream& operator() ( )
inline

Explicitly convert to Ostream for << operations.

Reimplemented from messageStream.

Definition at line 155 of file error.H.

Referenced by IOerror::operator()().

operator dictionary ( ) const

Create and return a dictionary.

Reimplemented in IOerror.

Definition at line 145 of file error.C.

References dictionary::add(), and string::replaceAll().

void printStack ( Foam::Ostream os)
static

Helper function to print a stack.

Definition at line 36 of file dummyPrintStack.C.

void exit ( const int  errNo = 1)

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

before exiting.

Reimplemented in IOerror.

Definition at line 168 of file error.C.

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

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

void abort ( )

Abort : used to stop code for fatal errors. Prints stack before.

exiting.

Reimplemented in IOerror.

Definition at line 209 of file error.C.

References JobInfo::abort(), Foam::abort(), Pstream::abort(), dictionary::add(), JobInfo::constructed, Foam::endl(), Foam::jobInfo, Pstream::parRun(), and Foam::Perr.

Referenced by Foam::abort().


Friends And Related Function Documentation

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

Member Data Documentation

string functionName_
protected

Definition at line 77 of file error.H.

Referenced by error::functionName().

string sourceFileName_
protected

Definition at line 78 of file error.H.

Referenced by error::sourceFileName().

label sourceFileLineNumber_
protected

Definition at line 79 of file error.H.

Referenced by error::sourceFileLineNumber().

bool abort_
protected

Definition at line 81 of file error.H.

bool throwExceptions_
protected

Definition at line 83 of file error.H.

Referenced by error::dontThrowExceptions(), and error::throwExceptions().

OStringStream* messageStreamPtr_
protected

Definition at line 84 of file error.H.

Referenced by error::error().


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