Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | 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)
 
 error (const dictionary &errDict)
 
 error (const error &err)
 
virtual ~error () noexcept
 
string message () const
 
void clear () const
 
const stringfunctionName () const noexcept
 
const stringsourceFileName () const noexcept
 
label sourceFileLineNumber () const noexcept
 
bool throwing () const noexcept
 
bool throwing (const bool on) noexcept
 
OSstreamstream ()
 
 operator OSstream & ()
 
OSstreamoperator() ()
 
OSstreamoperator() (const string &functionName)
 
OSstreamoperator() (const char *functionName, const char *sourceFileName, const int sourceFileLineNumber=0)
 
OSstreamoperator() (const string &functionName, const char *sourceFileName, const int sourceFileLineNumber=0)
 
 operator dictionary () const
 
void exit (const int errNo=1)
 
void abort ()
 
virtual void write (Ostream &os, const bool withTitle=true) const
 
bool throwExceptions (const bool on=true) noexcept
 
bool dontThrowExceptions () noexcept
 
- Public Member Functions inherited from messageStream
 messageStream (const string &title, const errorSeverity severity, const int maxErrors=0)
 
 messageStream (const dictionary &dict)
 
const stringtitle () const noexcept
 
int maxErrors () const noexcept
 
int maxErrors (int nErrors) noexcept
 
OSstreamstream (OSstream *alternative=nullptr)
 
OSstreammasterStream (const label communicator)
 
std::ostream & stdStream ()
 
 operator OSstream & ()
 
OSstreamoperator() ()
 
OSstreamoperator() (const string &functionName)
 
OSstreamoperator() (const char *functionName, const char *sourceFileName, const int sourceFileLineNumber=0)
 
OSstreamoperator() (const string &functionName, const char *sourceFileName, const int sourceFileLineNumber=0)
 
OSstreamoperator() (const char *functionName, const char *sourceFileName, const int sourceFileLineNumber, const string &ioFileName, const label ioStartLineNumber=-1, const label ioEndLineNumber=-1)
 
OSstreamoperator() (const char *functionName, const char *sourceFileName, const int sourceFileLineNumber, const IOstream &)
 
OSstreamoperator() (const char *functionName, const char *sourceFileName, const int sourceFileLineNumber, const dictionary &)
 

Static Public Member Functions

static bool master (const label communicator=-1)
 
static bool warnAboutAge (const int version) noexcept
 
static bool warnAboutAge (const char *what, const int version)
 
static void safePrintStack (std::ostream &os)
 
static void printStack (Ostream &os)
 
static bool useAbort ()
 

Protected Member Functions

void simpleExit (const int errNo, const bool isAbort)
 

Protected Attributes

string functionName_
 
string sourceFileName_
 
label sourceFileLineNumber_
 
bool throwing_
 
std::unique_ptr< 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, INFO_STDERR, WARNING, SERIOUS,
  FATAL
}
 
- Static Public Attributes inherited from messageStream
static int level
 
static int redirect
 

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
See also
Foam::errorManip Foam::errorManipArg

Definition at line 69 of file error.H.

Constructor & Destructor Documentation

◆ error() [1/3]

error ( const string title)
explicit

Definition at line 100 of file error.C.

◆ error() [2/3]

error ( const dictionary errDict)
explicit

Definition at line 112 of file error.C.

◆ error() [3/3]

error ( const error err)

Definition at line 124 of file error.C.

◆ ~error()

~error ( )
virtualnoexcept

Definition at line 138 of file error.C.

Member Function Documentation

◆ simpleExit()

void simpleExit ( const int  errNo,
const bool  isAbort 
)
protected

Definition at line 246 of file error.C.

References Foam::abort(), UPstream::abort(), Foam::endl(), Foam::exit(), UPstream::exit(), Foam::nl, UPstream::parRun(), Foam::Perr, error::printStack(), and error::useAbort().

Here is the call graph for this function:

◆ master()

bool master ( const label  communicator = -1)
static

Definition at line 34 of file error.C.

References UPstream::master(), and UPstream::parRun().

Referenced by Foam::expandLeadingTilde(), and Foam::warnCompatDegrees().

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

◆ warnAboutAge() [1/2]

bool warnAboutAge ( const int  version)
staticnoexcept

Definition at line 48 of file error.C.

References Foam::foamVersion::api, and Foam::foamVersion::version.

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

Here is the caller graph for this function:

◆ warnAboutAge() [2/2]

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

Definition at line 55 of file error.C.

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

Here is the call graph for this function:

◆ message()

Foam::string message ( ) const

Definition at line 312 of file error.C.

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

Here is the caller graph for this function:

◆ clear()

void clear ( ) const

Definition at line 318 of file error.C.

Referenced by motionSmootherAlgo::checkMesh().

Here is the caller graph for this function:

◆ functionName()

const string& functionName ( ) const
inlinenoexcept

Definition at line 147 of file error.H.

References error::functionName_.

◆ sourceFileName()

const string& sourceFileName ( ) const
inlinenoexcept

Definition at line 153 of file error.H.

References error::sourceFileName_.

◆ sourceFileLineNumber()

label sourceFileLineNumber ( ) const
inlinenoexcept

Definition at line 159 of file error.H.

References error::sourceFileLineNumber_.

◆ throwing() [1/2]

bool throwing ( ) const
inlinenoexcept

Definition at line 165 of file error.H.

References error::throwing_.

Referenced by functionObjectList::end(), functionObjectList::execute(), if(), IOobjectList::IOobjectList(), functionObjectList::read(), and error::throwExceptions().

Here is the caller graph for this function:

◆ throwing() [2/2]

bool throwing ( const bool  on)
inlinenoexcept

Definition at line 172 of file error.H.

References error::throwing_.

◆ stream()

Foam::OSstream & stream ( )

Definition at line 297 of file error.C.

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

Referenced by error::operator OSstream &(), error::operator()(), and Time::readDict().

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

◆ operator OSstream &()

operator OSstream & ( )
inline

Definition at line 186 of file error.H.

References error::stream().

Here is the call graph for this function:

◆ operator()() [1/4]

OSstream& operator() ( )
inline

Definition at line 192 of file error.H.

References error::stream().

Here is the call graph for this function:

◆ operator()() [2/4]

Foam::OSstream & operator() ( const string functionName)

Definition at line 145 of file error.C.

◆ operator()() [3/4]

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

Definition at line 158 of file error.C.

◆ operator()() [4/4]

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

Definition at line 184 of file error.C.

◆ operator dictionary()

operator dictionary ( ) const

◆ safePrintStack()

void safePrintStack ( std::ostream &  os)
static

Definition at line 25 of file dummyPrintStack.C.

◆ printStack()

void printStack ( Ostream os)
static

Definition at line 29 of file dummyPrintStack.C.

Referenced by UPstream::allToAll(), Foam::exitNow(), messageStream::masterStream(), Foam::reduce(), and error::simpleExit().

Here is the caller graph for this function:

◆ useAbort()

bool useAbort ( )
static

Definition at line 91 of file error.C.

References Switch::find(), and Foam::getEnv().

Referenced by Foam::exitNow(), and error::simpleExit().

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

◆ exit()

void exit ( const int  errNo = 1)

Definition at line 324 of file error.C.

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

Here is the caller graph for this function:

◆ abort()

void abort ( )

Definition at line 330 of file error.C.

Referenced by Foam::abort().

Here is the caller graph for this function:

◆ write()

void write ( Ostream os,
const bool  withTitle = true 
) const
virtual

Reimplemented in IOerror.

Definition at line 336 of file error.C.

References Foam::foamVersion::api, IOstream::bad(), messageStream::level, Foam::nl, os(), Foam::foamVersion::patch, and Foam::foamVersion::patched().

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

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

◆ throwExceptions()

bool throwExceptions ( const bool  on = true)
inlinenoexcept

Definition at line 256 of file error.H.

References error::throwing().

Referenced by error::dontThrowExceptions().

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

◆ dontThrowExceptions()

bool dontThrowExceptions ( )
inlinenoexcept

Definition at line 263 of file error.H.

References error::throwExceptions().

Here is the call graph for this function:

Member Data Documentation

◆ functionName_

string functionName_
protected

Definition at line 84 of file error.H.

Referenced by error::functionName().

◆ sourceFileName_

string sourceFileName_
protected

Definition at line 85 of file error.H.

Referenced by error::sourceFileName().

◆ sourceFileLineNumber_

label sourceFileLineNumber_
protected

Definition at line 86 of file error.H.

Referenced by error::sourceFileLineNumber().

◆ throwing_

bool throwing_
protected

Definition at line 87 of file error.H.

Referenced by error::throwing().

◆ messageStreamPtr_

std::unique_ptr<OStringStream> messageStreamPtr_
protected

Definition at line 88 of file error.H.


The documentation for this class was generated from the following files:
Foam::error::error
error(const string &title)
Definition: error.C:100
Foam::error::exit
void exit(const int errNo=1)
Definition: error.C:324
Foam::error::abort
void abort()
Definition: error.C:330