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)
180 const string& functionName
183 functionName_ = functionName;
184 sourceFileName_.clear();
185 sourceFileLineNumber_ = -1;
187 return this->stream();
193 const char* functionName,
194 const char* sourceFileName,
195 const int sourceFileLineNumber
198 functionName_.clear();
199 sourceFileName_.clear();
204 functionName_.assign(functionName);
209 sourceFileName_.assign(sourceFileName);
211 sourceFileLineNumber_ = sourceFileLineNumber;
213 return this->stream();
219 const string& functionName,
220 const char* sourceFileName,
221 const int sourceFileLineNumber
226 functionName.c_str(),
237 string oneLineMessage(message());
238 oneLineMessage.replaceAll(
"\n",
" ");
240 errDict.add(
"type", word(
"Foam::error"));
241 errDict.add(
"message", oneLineMessage);
242 errDict.add(
"function", functionName());
243 errDict.add(
"sourceFile", sourceFileName());
244 errDict.add(
"sourceFileLineNumber", sourceFileLineNumber());
252 void Foam::error::exiting(
const int errNo,
const bool isAbort)
259 error errorException(*
this);
264 throw errorException;
274 simpleExit(errNo, isAbort);
285 <<
"\nFOAM aborting (FOAM_ABORT set)\n" <<
endl;
294 <<
"\nFOAM parallel run aborting\n" <<
endl;
301 <<
"\nFOAM parallel run exiting\n" <<
endl;
310 <<
"\nFOAM aborting\n" <<
endl;
322 <<
"\nFOAM exiting\n" <<
endl;
333 if (!messageStreamPtr_)
335 messageStreamPtr_ = std::make_unique<OStringStream>();
337 else if (!messageStreamPtr_->good())
340 <<
"error::stream() : error stream has failed" 345 return *messageStreamPtr_;
351 if (messageStreamPtr_)
353 return messageStreamPtr_->str();
362 if (messageStreamPtr_)
364 messageStreamPtr_->reset();
371 exiting(errNo,
false);
389 if (withTitle && !title().empty())
391 os << title().c_str()
401 os << message().c_str();
404 const label lineNo = sourceFileLineNumber();
409 <<
" From " << functionName().c_str() <<
nl;
411 if (!sourceFileName().empty())
413 os <<
" in file " << sourceFileName().c_str();
417 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.