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)
181 const char* sourceFileName,
182 const int sourceFileLineNumber
185 functionName_ = std::move(functionName);
186 sourceFileName_.clear();
190 sourceFileName_.assign(sourceFileName);
193 sourceFileLineNumber_ = sourceFileLineNumber;
195 return this->stream();
201 const char* functionName,
202 const char* sourceFileName,
203 const int sourceFileLineNumber
206 functionName_.clear();
207 sourceFileName_.clear();
211 functionName_.assign(functionName);
215 sourceFileName_.assign(sourceFileName);
217 sourceFileLineNumber_ = sourceFileLineNumber;
219 return this->stream();
227 string oneLineMessage(message());
228 oneLineMessage.replaceAll(
"\n",
" ");
230 errDict.add(
"type", word(
"Foam::error"));
231 errDict.add(
"message", oneLineMessage);
232 errDict.add(
"function", functionName());
233 errDict.add(
"sourceFile", sourceFileName());
234 errDict.add(
"sourceFileLineNumber", sourceFileLineNumber());
242 void Foam::error::exiting(
const int errNo,
const bool isAbort)
249 error errorException(*
this);
254 throw errorException;
264 simpleExit(errNo, isAbort);
275 <<
"\nFOAM aborting (FOAM_ABORT set)\n" <<
endl;
284 <<
"\nFOAM parallel run aborting\n" <<
endl;
291 <<
"\nFOAM parallel run exiting\n" <<
endl;
300 <<
"\nFOAM aborting\n" <<
endl;
312 <<
"\nFOAM exiting\n" <<
endl;
323 if (!messageStreamPtr_)
325 messageStreamPtr_ = std::make_unique<OStringStream>();
327 else if (!messageStreamPtr_->good())
330 <<
"error::stream() : error stream has failed" 335 return *messageStreamPtr_;
341 if (messageStreamPtr_)
343 return messageStreamPtr_->str();
352 if (messageStreamPtr_)
354 messageStreamPtr_->reset();
361 exiting(errNo,
false);
379 if (withTitle && !title().empty())
381 os << title().c_str()
391 os << message().c_str();
394 const auto lineNo = sourceFileLineNumber();
399 <<
" From " << functionName().c_str() <<
nl;
401 if (!sourceFileName().empty())
403 os <<
" in file " << sourceFileName().c_str();
407 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.
static bool master(const int communicator=-1)
Like Pstream::master but with a Pstream::parRun guard in case Pstream has not yet been initialised...
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.
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)
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.
static void abort(int errNo=1)
Call MPI_Abort with no other checks or cleanup.
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.