Commit ffcff46f authored by Mark Olesen's avatar Mark Olesen Committed by Andrew Heather
Browse files

ENH: support trapping of IOerror exceptions in parallel (#1296)

- continuation of commit 0e7954c2

ENH: downgrade abort() to exit() in some places (#1238)
parent 849dffed
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2015 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2015-2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2011-2016 OpenFOAM Foundation
......@@ -187,31 +187,27 @@ void Foam::IOerror::exit(const int)
{
abort();
}
else if (throwExceptions_)
{
// Make a copy of the error to throw
IOerror errorException(*this);
// Reset the message buffer for the next error message
messageStreamPtr_->reset();
if (Pstream::parRun())
throw errorException;
}
else if (Pstream::parRun())
{
Perr<< endl << *this << endl
Perr<< nl << *this << nl
<< "\nFOAM parallel run exiting\n" << endl;
Pstream::exit(1);
}
else
{
if (throwExceptions_)
{
// Make a copy of the error to throw
IOerror errorException(*this);
// Reset the message buffer for the next error message
messageStreamPtr_->reset();
throw errorException;
}
else
{
Perr<< endl << *this << endl
<< "\nFOAM exiting\n" << endl;
std::exit(1);
}
Perr<< nl << *this << nl
<< "\nFOAM exiting\n" << endl;
std::exit(1);
}
}
......@@ -226,38 +222,39 @@ void Foam::IOerror::abort()
if (env("FOAM_ABORT"))
{
Perr<< endl << *this << endl
Perr<< nl << *this << nl
<< "\nFOAM aborting (FOAM_ABORT set)\n" << endl;
printStack(Perr);
std::abort();
}
else if (throwExceptions_)
{
// Make a copy of the error to throw
IOerror errorException(*this);
if (Pstream::parRun())
// Reset the message buffer for the next error message
messageStreamPtr_->reset();
throw errorException;
}
else if (Pstream::parRun())
{
Perr<< endl << *this << endl
Perr<< nl << *this << nl
<< "\nFOAM parallel run aborting\n" << endl;
printStack(Perr);
Pstream::abort();
}
else
{
if (throwExceptions_)
{
// Make a copy of the error to throw
IOerror errorException(*this);
// Reset the message buffer for the next error message
messageStreamPtr_->reset();
Perr<< nl << *this << nl
<< "\nFOAM aborting\n" << endl;
printStack(Perr);
throw errorException;
}
else
{
Perr<< endl << *this << endl
<< "\nFOAM aborting\n" << endl;
printStack(Perr);
std::abort();
}
#ifdef _WIN32
std::exit(1); // Prefer exit() to avoid unnecessary warnings
#else
std::abort();
#endif
}
}
......@@ -271,7 +268,7 @@ void Foam::IOerror::write(Ostream& os, const bool includeTitle) const
{
os << title().c_str() << nl;
}
os << message().c_str() << nl << endl;
os << message().c_str() << nl << nl;
os << "file: " << ioFileName().c_str();
......@@ -288,7 +285,7 @@ void Foam::IOerror::write(Ostream& os, const bool includeTitle) const
if (IOerror::level >= 2 && sourceFileLineNumber())
{
os << nl << nl
<< " From function " << functionName().c_str() << endl
<< " From function " << functionName().c_str() << nl
<< " in file " << sourceFileName().c_str()
<< " at line " << sourceFileLineNumber() << '.';
}
......@@ -296,6 +293,8 @@ void Foam::IOerror::write(Ostream& os, const bool includeTitle) const
}
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
Foam::Ostream& Foam::operator<<(Ostream& os, const IOerror& err)
{
err.write(os);
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2015-2018 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2015-2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2011-2014 OpenFOAM Foundation
......@@ -82,7 +82,7 @@ Foam::error::error(const string& title)
{
if (!messageStreamPtr_->good())
{
Perr<< endl
Perr<< nl
<< "error::error(const string& title) : cannot open error stream"
<< endl;
exit(1);
......@@ -102,7 +102,7 @@ Foam::error::error(const dictionary& errDict)
{
if (!messageStreamPtr_->good())
{
Perr<< endl
Perr<< nl
<< "error::error(const dictionary& errDict) : "
"cannot open error stream"
<< endl;
......@@ -170,7 +170,7 @@ Foam::error::operator Foam::OSstream&()
{
if (!messageStreamPtr_->good())
{
Perr<< endl
Perr<< nl
<< "error::operator OSstream&() : error stream has failed"
<< endl;
abort();
......@@ -223,8 +223,7 @@ void Foam::error::exit(const int errNo)
{
abort();
}
if (throwExceptions_)
else if (throwExceptions_)
{
// Make a copy of the error to throw
error errorException(*this);
......@@ -236,13 +235,13 @@ void Foam::error::exit(const int errNo)
}
else if (Pstream::parRun())
{
Perr<< endl << *this << endl
Perr<< nl << *this << nl
<< "\nFOAM parallel run exiting\n" << endl;
Pstream::exit(errNo);
}
else
{
Perr<< endl << *this << endl
Perr<< nl << *this << nl
<< "\nFOAM exiting\n" << endl;
std::exit(errNo);
}
......@@ -259,13 +258,12 @@ void Foam::error::abort()
if (env("FOAM_ABORT"))
{
Perr<< endl << *this << endl
Perr<< nl << *this << nl
<< "\nFOAM aborting (FOAM_ABORT set)\n" << endl;
printStack(Perr);
std::abort();
}
if (throwExceptions_)
else if (throwExceptions_)
{
// Make a copy of the error to throw
error errorException(*this);
......@@ -277,17 +275,22 @@ void Foam::error::abort()
}
else if (Pstream::parRun())
{
Perr<< endl << *this << endl
Perr<< nl << *this << nl
<< "\nFOAM parallel run aborting\n" << endl;
printStack(Perr);
Pstream::abort();
}
else
{
Perr<< endl << *this << endl
Perr<< nl << *this << nl
<< "\nFOAM aborting\n" << endl;
printStack(Perr);
#ifdef _WIN32
std::exit(1); // Prefer exit() to avoid unnecessary warnings
#else
std::abort();
#endif
}
}
......@@ -297,14 +300,14 @@ void Foam::error::write(Ostream& os, const bool includeTitle) const
os << nl;
if (includeTitle)
{
os << title().c_str() << endl;
os << title().c_str() << nl;
}
os << message().c_str();
if (error::level >= 2 && sourceFileLineNumber())
{
os << nl << nl
<< " From function " << functionName().c_str() << endl
<< " From function " << functionName().c_str() << nl
<< " in file " << sourceFileName().c_str()
<< " at line " << sourceFileLineNumber() << '.';
}
......
......@@ -57,11 +57,6 @@ SourceFiles
namespace Foam
{
// Forward declarations
class error;
Ostream& operator<<(Ostream& os, const error& err);
/*---------------------------------------------------------------------------*\
Class error Declaration
\*---------------------------------------------------------------------------*/
......@@ -112,7 +107,7 @@ public:
static void warnAboutAge(const char* what, const int version);
// Member functions
// Member Functions
string message() const;
......@@ -212,19 +207,9 @@ public:
//- Print error message
void write(Ostream& os, const bool includeTitle = true) const;
// Ostream operator
friend Ostream& operator<<(Ostream& os, const error& err);
};
// Forward declarations
class IOerror;
Ostream& operator<<(Ostream& os, const IOerror& err);
/*---------------------------------------------------------------------------*\
Class IOerror Declaration
\*---------------------------------------------------------------------------*/
......@@ -328,12 +313,16 @@ public:
//- Print error message
void write(Ostream& os, const bool includeTitle = true) const;
};
// Ostream operator
// * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
friend Ostream& operator<<(Ostream& os, const IOerror& err);
};
//- Ostream operator
Ostream& operator<<(Ostream& os, const error& err);
//- Ostream operator
Ostream& operator<<(Ostream& os, const IOerror& err);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......
......@@ -123,7 +123,7 @@ inline void Foam::fileName::stripInvalid()
std::cerr
<< " For debug level (= " << debug
<< ") > 1 this is considered fatal" << std::endl;
std::abort();
std::exit(1);
}
removeRepeated('/');
......
......@@ -155,7 +155,7 @@ inline void Foam::word::stripInvalid()
std::cerr
<< " For debug level (= " << debug
<< ") > 1 this is considered fatal" << std::endl;
std::abort();
std::exit(1);
}
}
}
......
......@@ -33,6 +33,7 @@ License
void Foam::UPstream::addValidParOptions(HashTable<string>& validParOptions)
{}
bool Foam::UPstream::initNull()
{
WarningInFunction
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment