OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

error Class Reference

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

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.

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_

Friends

Ostreamoperator<< (Ostream &, const error &)

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


Constructor & Destructor Documentation

error ( const string title  ) 

Construct from title string.

Definition at line 28 of file error.C.

References IOstream::good(), and error::messageStreamPtr_.

Here is the call graph for this function:

error ( const dictionary errDict  ) 

Construct from dictionary.

Definition at line 49 of file error.C.

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

Here is the call graph for this function:

error ( const error err  ) 

Construct as copy.

Definition at line 71 of file error.C.

~error (  )  throw () [virtual]

Definition at line 86 of file error.C.


Member Function Documentation

Foam::string message (  )  const

Definition at line 156 of file error.C.

const string& functionName (  )  const [inline]

Definition at line 104 of file error.H.

const string& sourceFileName (  )  const [inline]

Definition at line 109 of file error.H.

References error::functionName_.

label sourceFileLineNumber (  )  const [inline]

Definition at line 114 of file error.H.

References error::sourceFileName_.

void throwExceptions (  )  [inline]

Definition at line 119 of file error.H.

References error::sourceFileLineNumber_.

Referenced by Foam::tryCalc().

Here is the caller graph for this function:

void dontThrowExceptions (  )  [inline]

Definition at line 124 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 93 of file error.C.

References error::messageStreamPtr_.

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

Reimplemented from messageStream.

Definition at line 109 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 124 of file error.C.

Referenced by error::operator()().

Here is the caller graph for this function:

OSstream& operator() (  )  [inline]

Explicitly convert to Ostream for << operations.

Reimplemented from messageStream.

Definition at line 154 of file error.H.

References error::operator OSstream &().

Here is the call graph for this function:

operator dictionary (  )  const

Create and return a dictionary.

Reimplemented in IOerror.

Definition at line 139 of file error.C.

void printStack ( Ostream os  )  [static]

Helper function to print a stack.

Definition at line 22 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 162 of file error.C.

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

Here is the caller graph for this function:

void abort (  ) 

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

exiting.

Reimplemented in IOerror.

Definition at line 200 of file error.C.

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

Here is the call graph for this function:


Friends And Related Function Documentation

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


Member Data Documentation

string functionName_ [protected]

Definition at line 72 of file error.H.

Referenced by error::sourceFileName().

string sourceFileName_ [protected]

Definition at line 73 of file error.H.

Referenced by error::sourceFileLineNumber().

Definition at line 74 of file error.H.

Referenced by error::throwExceptions().

bool abort_ [protected]

Definition at line 76 of file error.H.

bool throwExceptions_ [protected]

Definition at line 78 of file error.H.

Referenced by error::dontThrowExceptions().

Definition at line 79 of file error.H.

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


The documentation for this class was generated from the following files:
Copyright © 2000-2009 OpenCFD Ltd