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),
134 messageStreamPtr_(nullptr)
142 functionName_(errDict.
get<
string>(
"functionName")),
144 sourceFileLineNumber_(errDict.
get<label>(
"sourceFileLineNumber")),
146 messageStreamPtr_(nullptr)
154 functionName_(err.functionName_),
155 sourceFileName_(err.sourceFileName_),
156 sourceFileLineNumber_(err.sourceFileLineNumber_),
157 throwing_(err.throwing_),
158 messageStreamPtr_(nullptr)
177 const string& functionName
180 functionName_ = functionName;
181 sourceFileName_.clear();
182 sourceFileLineNumber_ = -1;
184 return this->stream();
190 const char* functionName,
191 const char* sourceFileName,
192 const int sourceFileLineNumber
195 functionName_.clear();
196 sourceFileName_.clear();
201 functionName_.assign(functionName);
206 sourceFileName_.assign(sourceFileName);
208 sourceFileLineNumber_ = sourceFileLineNumber;
210 return this->stream();
216 const string& functionName,
217 const char* sourceFileName,
218 const int sourceFileLineNumber
223 functionName.c_str(),
234 string oneLineMessage(message());
235 oneLineMessage.replaceAll(
"\n",
" ");
237 errDict.add(
"type", word(
"Foam::error"));
238 errDict.add(
"message", oneLineMessage);
239 errDict.add(
"function", functionName());
240 errDict.add(
"sourceFile", sourceFileName());
241 errDict.add(
"sourceFileLineNumber", sourceFileLineNumber());
249 void Foam::error::exiting(
const int errNo,
const bool isAbort)
256 error errorException(*
this);
261 throw errorException;
271 simpleExit(errNo, isAbort);
282 <<
"\nFOAM aborting (FOAM_ABORT set)\n" <<
endl;
291 <<
"\nFOAM parallel run aborting\n" <<
endl;
298 <<
"\nFOAM parallel run exiting\n" <<
endl;
307 <<
"\nFOAM aborting\n" <<
endl;
319 <<
"\nFOAM exiting\n" <<
endl;
330 if (!messageStreamPtr_)
332 messageStreamPtr_ = std::make_unique<OStringStream>();
334 else if (!messageStreamPtr_->good())
337 <<
"error::stream() : error stream has failed" 342 return *messageStreamPtr_;
348 if (messageStreamPtr_)
350 return messageStreamPtr_->str();
359 if (messageStreamPtr_)
361 messageStreamPtr_->reset();
368 exiting(errNo,
false);
386 if (withTitle && !title().empty())
388 os << title().c_str()
398 os << message().c_str();
401 const label lineNo = sourceFileLineNumber();
406 <<
" From " << functionName().c_str() <<
nl;
408 if (!sourceFileName().empty())
410 os <<
" in file " << sourceFileName().c_str();
414 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 accumulated error messages.
bool bad() const noexcept
True if stream is corrupted.
std::unique_ptr< OStringStream > messageStreamPtr_
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.
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.
error(const char *title)
Construct from title string.
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.