51 { handlerTypes::DEFAULT,
"default" },
52 { handlerTypes::IGNORE,
"ignore" },
54 { handlerTypes::STRICT,
"strict" },
95 - (12 * (version/100) + (version % 100))
102 <<
" This " << what <<
" is very old.\n"
108 <<
" This " << what <<
" is " << months <<
" months old.\n"
130 functionName_(
"unknown"),
142 functionName_(errDict.get<
string>(
"functionName")),
154 functionName_(err.functionName_),
155 sourceFileName_(err.sourceFileName_),
156 sourceFileLineNumber_(err.sourceFileLineNumber_),
157 throwing_(err.throwing_),
158 messageStreamPtr_(nullptr)
165 messageStreamPtr_.reset(new OStringStream(*err.messageStreamPtr_));
181 const char* sourceFileName,
182 const int sourceFileLineNumber
185 functionName_ = std::move(functionName);
186 sourceFileName_.clear();
190 sourceFileName_.assign(sourceFileName);
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();
223Foam::error::operator Foam::dictionary()
const
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());
242void Foam::error::exiting(
const int errNo,
const bool isAbort)
249 error errorException(*
this);
254 throw errorException;
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_)
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 <<
'.';
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
Input/output from string buffers.
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
static void shutdown()
Simple shutdown (finalize) of JobInfo.
static bool constructed
Global value for constructed job info.
Generic output stream using a standard (STL) stream.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
virtual bool write(const token &tok)=0
Write token to stream or otherwise handle it.
static Switch find(const char *s)
Find switchType for the given string, returning a Switch that can be tested for good() or bad().
static bool parRun(const bool on) noexcept
Set as parallel run on/off.
static bool master(const label communicator=worldComm)
True if process corresponds to the master rank in the communicator.
static void exit(int errNo=1)
Shutdown (finalize) MPI as required and exit program with errNo.
static void abort(int errNo=1)
Call MPI_Abort with no other checks or cleanup.
static bool & parRun() noexcept
Test if this a parallel run.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
entry * add(entry *entryPtr, bool mergeEntry=false)
Add a new entry.
Class to handle errors and exceptions in a simple, consistent stream-based manner.
const string & sourceFileName() const noexcept
The currently defined source-file name for output messages.
const string & functionName() const noexcept
The currently defined function name for output messages.
OSstream & stream()
Return OSstream for output operations.
static bool master(const int 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.
handlerTypes
Handling of errors. The exact handling depends on the local context.
@ WARN
Warn on errors/problems.
std::unique_ptr< OStringStream > messageStreamPtr_
virtual void write(Ostream &os, const bool withTitle=true) const
Print error message.
void exit(const int errNo=1)
Exit : can be called for any error to exit program.
void simpleExit(const int errNo, const bool isAbort)
Exit or abort, without throwing or job control handling.
static bool warnAboutAge(const int version) noexcept
Test if an age warning should be emitted.
static bool useAbort()
True if FOAM_ABORT is on.
static void printStack(Ostream &os, int size=-1)
Helper function to print a stack, with optional upper limit.
static const Enum< handlerTypes > handlerNames
Names of the error handler types.
void abort()
Abort : used to stop code for fatal errors.
virtual ~error() noexcept
Destructor.
error(const char *title)
Construct from title string.
void clear() const
Clear any accumulated error messages.
int sourceFileLineNumber() const noexcept
The currently defined source-file line number for output messages.
int sourceFileLineNumber_
Handle output messages in a simple, consistent stream-based manner.
messageStream(errorSeverity severity, int maxErrors=0, bool use_stderr=false)
Construct untitled with given characteristics.
static int level
The output level (verbosity) of messages.
const string & title() const noexcept
The title of this error type.
A class for handling character strings derived from std::string.
A class for handling words, derived from Foam::string.
OBJstream os(runTime.globalPath()/outputName)
const std::string patch
OpenFOAM patch number as a std::string.
const int api
OpenFOAM api number (integer) corresponding to the value of OPENFOAM at the time of compilation.
bool patched()
Test if the patch string appears to be in use, which is when it is defined (non-zero).
string getEnv(const std::string &envName)
Get environment value for given envName.
prefixOSstream Perr
OSstream wrapped stderr (std::cerr) with parallel prefix.
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces).
Ostream & endl(Ostream &os)
Add newline and flush stream.
errorManip< error > abort(error &err)
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
constexpr char nl
The newline '\n' character (0x0a).