51 { handlerTypes::DEFAULT,
"default" },
52 { handlerTypes::IGNORE,
"ignore" },
53 { handlerTypes::WARN,
"warn" },
54 { handlerTypes::STRICT,
"strict" },
102 <<
" This " << what <<
" is very old.\n" 108 <<
" This " << what <<
" is " << months <<
" months old.\n" 130 functionName_(
"unknown"),
131 sourceFileName_(
"unknown"),
132 sourceFileLineNumber_(0),
142 functionName_(errDict.
get<
string>(
"functionName")),
144 sourceFileLineNumber_(errDict.
get<label>(
"sourceFileLineNumber")),
154 functionName_(err.functionName_),
155 sourceFileName_(err.sourceFileName_),
156 sourceFileLineNumber_(err.sourceFileLineNumber_),
157 throwing_(err.throwing_),
172 const string& functionName
175 functionName_ = functionName;
176 sourceFileName_.clear();
177 sourceFileLineNumber_ = -1;
185 const char* functionName,
186 const char* sourceFileName,
187 const int sourceFileLineNumber
190 functionName_.clear();
191 sourceFileName_.clear();
196 functionName_.assign(functionName);
201 sourceFileName_.assign(sourceFileName);
203 sourceFileLineNumber_ = sourceFileLineNumber;
205 return this->stream();
211 const string& functionName,
212 const char* sourceFileName,
213 const int sourceFileLineNumber
218 functionName.c_str(),
229 string oneLineMessage(message());
230 oneLineMessage.replaceAll(
"\n",
" ");
232 errDict.add(
"type", word(
"Foam::error"));
233 errDict.add(
"message", oneLineMessage);
234 errDict.add(
"function", functionName());
235 errDict.add(
"sourceFile", sourceFileName());
236 errDict.add(
"sourceFileLineNumber", sourceFileLineNumber());
244 void Foam::error::exiting(
const int errNo,
const bool isAbort)
251 error errorException(*
this);
254 messageStreamPtr_->reset();
256 throw errorException;
266 simpleExit(errNo, isAbort);
277 <<
"\nFOAM aborting (FOAM_ABORT set)\n" <<
endl;
286 <<
"\nFOAM parallel run aborting\n" <<
endl;
293 <<
"\nFOAM parallel run exiting\n" <<
endl;
302 <<
"\nFOAM aborting\n" <<
endl;
314 <<
"\nFOAM exiting\n" <<
endl;
326 if (!messageStreamPtr_->good())
329 <<
"error::stream() : error stream has failed" 334 return *messageStreamPtr_;
340 return messageStreamPtr_->str();
346 return messageStreamPtr_->reset();
352 exiting(errNo,
false);
370 if (withTitle && !title().empty())
372 os << title().c_str()
382 os << message().c_str();
385 const label lineNo = sourceFileLineNumber();
387 if (
error::level >= 2 && lineNo && !functionName().empty())
390 <<
" From " << functionName().c_str() <<
nl;
392 if (!sourceFileName().empty())
394 os <<
" in file " << sourceFileName().c_str();
398 os <<
" at line " << lineNo <<
'.';
List< ReturnType > get(const UPtrList< T > &list, const AccessOp &aop)
List of values generated by applying the access operation to each list item.
prefixOSstream Perr
OSstream wrapped stderr (std::cerr) with parallel prefix.
Generic output stream using a standard (STL) stream.
void clear() const
Clear any messages.
bool bad() const noexcept
True if stream is corrupted.
handlerTypes
Handling of errors. The exact handling depends on the local context.
errorManipArg< error, int > exit(error &err, const int errNo=1)
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Input/output from string buffers.
constexpr char nl
The newline '\n' character (0x0a)
static void shutdown()
Simple shutdown (finalize) of JobInfo.
Ostream & endl(Ostream &os)
Add newline and flush stream.
static bool & parRun() noexcept
Test if this a parallel run.
virtual ~error() noexcept
Destructor.
bool patched()
Test if the patch string appears to be in use, which is when it is defined (non-zero).
entry * add(entry *entryPtr, bool mergeEntry=false)
Add a new entry.
Handle output messages in a simple, consistent stream-based manner.
string getEnv(const std::string &envName)
Get environment value for given envName.
void exit(const int errNo=1)
Exit : can be called for any error to exit program.
static bool warnAboutAge(const int version) noexcept
Test if an age warning should be emitted.
error(const string &title)
Construct from title string.
Class to handle errors and exceptions in a simple, consistent stream-based manner.
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
static void exit(int errNo=1)
Shutdown (finalize) MPI as required and exit program with errNo.
static bool useAbort()
True if FOAM_ABORT is on.
static bool master(const label communicator=-1)
Like Pstream::master but with a Pstream::parRun guard in case Pstream has not yet been initialised...
string message() const
The accumulated error message.
void abort()
Abort : used to stop code for fatal errors.
virtual void write(Ostream &os, const bool withTitle=true) const
Print error message.
virtual bool write(const token &tok)=0
Write token to stream or otherwise handle it.
errorManip< error > abort(error &err)
const int api
OpenFOAM api number (integer) corresponding to the value of OPENFOAM at the time of compilation...
An Ostream is an abstract base class for all output systems (streams, files, token lists...
OBJstream os(runTime.globalPath()/outputName)
static void abort()
Call MPI_Abort with no other checks or cleanup.
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
const std::string version
OpenFOAM version (name or stringified number) as a std::string.
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
OSstream & stream()
Return OSstream for output operations.
static bool master(const label communicator=worldComm)
True if process corresponds to the master rank in the communicator.
const std::string patch
OpenFOAM patch number as a std::string.
static void printStack(Ostream &os, int size=-1)
Helper function to print a stack, with optional upper limit.
A class for handling character strings derived from std::string.
Output to string buffer, using a OSstream. Always UNCOMPRESSED.
static Switch find(const std::string &str)
Find switchType for the given string, returning as a Switch that can be tested for good() or bad()...
static int level
The output level (verbosity) of messages.
static bool constructed
Global value for constructed job info.
static const Enum< handlerTypes > handlerNames
Names of the error handler types.
void simpleExit(const int errNo, const bool isAbort)
Exit or abort, without throwing or job control handling.