FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

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 string &  functionName () const
const string &  sourceFileName () const
label  sourceFileLineNumber () const
void  throwExceptions ()
void  dontThrowExceptions ()
OSstream &  operator() (const char *functionName, const char *sourceFileName, const int sourceFileLineNumber=0)
 Convert to Ostream.
OSstream &  operator() (const string &functionName, const char *sourceFileName, const int sourceFileLineNumber=0)
 operator OSstream & ()
 Convert to Ostream.
OSstream &  operator() ()
 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.

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_
OStringStream *  messageStreamPtr_

Friends

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

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.

Referenced by error::operator()().

OSstream& operator() (  ) [inline]

Explicitly convert to Ostream for << operations.

Reimplemented from messageStream.

Definition at line 155 of file error.H.

References error::operator OSstream &().

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(), Foam::exit(), Pstream::exit(), JobInfo::exit(), Foam::jobInfo, Pstream::parRun(), and Foam::Perr.

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

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 Pstream::abort(), Foam::abort(), JobInfo::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().

Definition at line 84 of file error.H.

Referenced by error::error().


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