Go to the documentation of this file.
51 <<
" This " << what <<
" is considered to be VERY old!\n"
64 <<
" This " << what <<
" is deemed to be " << months
79 functionName_(
"unknown"),
80 sourceFileName_(
"unknown"),
81 sourceFileLineNumber_(0),
82 throwExceptions_(false),
88 <<
"error::error(const string&) : cannot open error stream"
99 functionName_(errDict.get<
string>(
"functionName")),
100 sourceFileName_(errDict.get<
string>(
"sourceFileName")),
101 sourceFileLineNumber_(errDict.get<label>(
"sourceFileLineNumber")),
102 throwExceptions_(false),
108 <<
"error::error(const dictionary&) : cannot open error stream"
119 functionName_(err.functionName_),
120 sourceFileName_(err.sourceFileName_),
121 sourceFileLineNumber_(err.sourceFileLineNumber_),
122 throwExceptions_(err.throwExceptions_),
131 delete messageStreamPtr_;
139 const string& functionName
142 functionName_ = functionName;
143 sourceFileName_.clear();
144 sourceFileLineNumber_ = -1;
152 const char* functionName,
153 const char* sourceFileName,
154 const int sourceFileLineNumber
157 functionName_ = functionName;
158 sourceFileName_ = sourceFileName;
159 sourceFileLineNumber_ = sourceFileLineNumber;
167 const string& functionName,
168 const char* sourceFileName,
169 const int sourceFileLineNumber
174 functionName.c_str(),
183 if (!messageStreamPtr_->good())
186 <<
"error::operator OSstream&() : error stream has failed"
191 return *messageStreamPtr_;
199 string oneLineMessage(message());
200 oneLineMessage.replaceAll(
"\n",
" ");
202 errDict.add(
"type", word(
"Foam::error"));
203 errDict.add(
"message", oneLineMessage);
204 errDict.add(
"function", functionName());
205 errDict.add(
"sourceFile", sourceFileName());
206 errDict.add(
"sourceFileLineNumber", sourceFileLineNumber());
216 return messageStreamPtr_->str();
222 return messageStreamPtr_->reset();
226 void Foam::error::exitOrAbort(
const int errNo,
const bool isAbort)
244 <<
"\nFOAM aborting (FOAM_ABORT set)\n" <<
endl;
248 else if (throwExceptions_)
251 error errorException(*
this);
254 messageStreamPtr_->reset();
256 throw errorException;
263 <<
"\nFOAM parallel run aborting\n" <<
endl;
270 <<
"\nFOAM parallel run exiting\n" <<
endl;
279 <<
"\nFOAM aborting\n" <<
endl;
291 <<
"\nFOAM exiting\n" <<
endl;
300 exitOrAbort(errNo,
hasEnv(
"FOAM_ABORT"));
306 exitOrAbort(1,
true);
318 if (includeTitle && !title().empty())
320 os << title().c_str() <<
nl;
322 os << message().c_str();
325 const label lineNo = sourceFileLineNumber();
327 if (
error::level >= 2 && lineNo && !functionName().empty())
330 <<
" From " << functionName().c_str() <<
nl;
332 if (!sourceFileName().empty())
334 os <<
" in file " << sourceFileName().c_str();
338 os <<
" at line " << lineNo <<
'.';
void exit()
End with "termination=exit".
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
Class to handle messaging in a simple, consistent stream-based manner.
static bool & parRun()
Is this a parallel run?
static int level
Control the output verbosity of messageStream.
Input/output from string buffers.
static void abort()
Call MPI_Abort with no other checks or cleanup.
Ostream & endl(Ostream &os)
Add newline and flush stream.
A class for handling character strings derived from std::string.
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
bool hasEnv(const std::string &envName)
True if environment variable of given name is defined.
error(const string &title)
Construct from title string.
Generic output stream using a standard (STL) stream.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
bool bad() const
Return true if stream is corrupted.
string message() const
The accumulated error message.
errorManip< error > abort(error &err)
void exit(const int errNo=1)
Exit : can be called for any error to exit program.
errorManipArg< error, int > exit(error &err, const int errNo=1)
const std::string version
OpenFOAM version (name or stringified number) as a std::string.
virtual ~error() noexcept
Destructor.
prefixOSstream Perr
An Ostream wrapper for parallel output to std::cerr.
static void warnAboutAge(const char *what, const int version)
Emit warning on stderr about something being old.
static bool constructed
Global value for constructed job info.
void abort()
Abort : used to stop code for fatal errors.
Output to string buffer, using a OSstream.
OStringStream * messageStreamPtr_
void clear() const
Clear any messages.
entry * add(entry *entryPtr, bool mergeEntry=false)
Add a new entry.
void write(Ostream &os, const bool includeTitle=true) const
Print error message.
void abort()
End with "termination=abort".
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
bool good() const
Return true if next operation might succeed.
Class to handle errors and exceptions in a simple, consistent stream-based manner.
static void exit(int errNo=1)
Shutdown (finalize) MPI as required and exit program with errNo.