mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: support trapping of IOerror exceptions in parallel (#1296)
- continuation of commit 0e7954c22b
ENH: downgrade abort() to exit() in some places (#1238)
This commit is contained in:
committed by
Andrew Heather
parent
849dffedb8
commit
ffcff46f18
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2015 OpenCFD Ltd.
|
\\ / A nd | Copyright (C) 2015-2019 OpenCFD Ltd.
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
| Copyright (C) 2011-2016 OpenFOAM Foundation
|
| Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||||
@ -187,16 +187,7 @@ void Foam::IOerror::exit(const int)
|
|||||||
{
|
{
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
else if (throwExceptions_)
|
||||||
if (Pstream::parRun())
|
|
||||||
{
|
|
||||||
Perr<< endl << *this << endl
|
|
||||||
<< "\nFOAM parallel run exiting\n" << endl;
|
|
||||||
Pstream::exit(1);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (throwExceptions_)
|
|
||||||
{
|
{
|
||||||
// Make a copy of the error to throw
|
// Make a copy of the error to throw
|
||||||
IOerror errorException(*this);
|
IOerror errorException(*this);
|
||||||
@ -206,13 +197,18 @@ void Foam::IOerror::exit(const int)
|
|||||||
|
|
||||||
throw errorException;
|
throw errorException;
|
||||||
}
|
}
|
||||||
|
else if (Pstream::parRun())
|
||||||
|
{
|
||||||
|
Perr<< nl << *this << nl
|
||||||
|
<< "\nFOAM parallel run exiting\n" << endl;
|
||||||
|
Pstream::exit(1);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Perr<< endl << *this << endl
|
Perr<< nl << *this << nl
|
||||||
<< "\nFOAM exiting\n" << endl;
|
<< "\nFOAM exiting\n" << endl;
|
||||||
std::exit(1);
|
std::exit(1);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -226,22 +222,12 @@ void Foam::IOerror::abort()
|
|||||||
|
|
||||||
if (env("FOAM_ABORT"))
|
if (env("FOAM_ABORT"))
|
||||||
{
|
{
|
||||||
Perr<< endl << *this << endl
|
Perr<< nl << *this << nl
|
||||||
<< "\nFOAM aborting (FOAM_ABORT set)\n" << endl;
|
<< "\nFOAM aborting (FOAM_ABORT set)\n" << endl;
|
||||||
printStack(Perr);
|
printStack(Perr);
|
||||||
std::abort();
|
std::abort();
|
||||||
}
|
}
|
||||||
|
else if (throwExceptions_)
|
||||||
if (Pstream::parRun())
|
|
||||||
{
|
|
||||||
Perr<< endl << *this << endl
|
|
||||||
<< "\nFOAM parallel run aborting\n" << endl;
|
|
||||||
printStack(Perr);
|
|
||||||
Pstream::abort();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (throwExceptions_)
|
|
||||||
{
|
{
|
||||||
// Make a copy of the error to throw
|
// Make a copy of the error to throw
|
||||||
IOerror errorException(*this);
|
IOerror errorException(*this);
|
||||||
@ -251,13 +237,24 @@ void Foam::IOerror::abort()
|
|||||||
|
|
||||||
throw errorException;
|
throw errorException;
|
||||||
}
|
}
|
||||||
|
else if (Pstream::parRun())
|
||||||
|
{
|
||||||
|
Perr<< nl << *this << nl
|
||||||
|
<< "\nFOAM parallel run aborting\n" << endl;
|
||||||
|
printStack(Perr);
|
||||||
|
Pstream::abort();
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Perr<< endl << *this << endl
|
Perr<< nl << *this << nl
|
||||||
<< "\nFOAM aborting\n" << endl;
|
<< "\nFOAM aborting\n" << endl;
|
||||||
printStack(Perr);
|
printStack(Perr);
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
std::exit(1); // Prefer exit() to avoid unnecessary warnings
|
||||||
|
#else
|
||||||
std::abort();
|
std::abort();
|
||||||
}
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -271,7 +268,7 @@ void Foam::IOerror::write(Ostream& os, const bool includeTitle) const
|
|||||||
{
|
{
|
||||||
os << title().c_str() << nl;
|
os << title().c_str() << nl;
|
||||||
}
|
}
|
||||||
os << message().c_str() << nl << endl;
|
os << message().c_str() << nl << nl;
|
||||||
|
|
||||||
os << "file: " << ioFileName().c_str();
|
os << "file: " << ioFileName().c_str();
|
||||||
|
|
||||||
@ -288,7 +285,7 @@ void Foam::IOerror::write(Ostream& os, const bool includeTitle) const
|
|||||||
if (IOerror::level >= 2 && sourceFileLineNumber())
|
if (IOerror::level >= 2 && sourceFileLineNumber())
|
||||||
{
|
{
|
||||||
os << nl << nl
|
os << nl << nl
|
||||||
<< " From function " << functionName().c_str() << endl
|
<< " From function " << functionName().c_str() << nl
|
||||||
<< " in file " << sourceFileName().c_str()
|
<< " in file " << sourceFileName().c_str()
|
||||||
<< " at line " << sourceFileLineNumber() << '.';
|
<< " 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)
|
Foam::Ostream& Foam::operator<<(Ostream& os, const IOerror& err)
|
||||||
{
|
{
|
||||||
err.write(os);
|
err.write(os);
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2015-2018 OpenCFD Ltd.
|
\\ / A nd | Copyright (C) 2015-2019 OpenCFD Ltd.
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
| Copyright (C) 2011-2014 OpenFOAM Foundation
|
| Copyright (C) 2011-2014 OpenFOAM Foundation
|
||||||
@ -82,7 +82,7 @@ Foam::error::error(const string& title)
|
|||||||
{
|
{
|
||||||
if (!messageStreamPtr_->good())
|
if (!messageStreamPtr_->good())
|
||||||
{
|
{
|
||||||
Perr<< endl
|
Perr<< nl
|
||||||
<< "error::error(const string& title) : cannot open error stream"
|
<< "error::error(const string& title) : cannot open error stream"
|
||||||
<< endl;
|
<< endl;
|
||||||
exit(1);
|
exit(1);
|
||||||
@ -102,7 +102,7 @@ Foam::error::error(const dictionary& errDict)
|
|||||||
{
|
{
|
||||||
if (!messageStreamPtr_->good())
|
if (!messageStreamPtr_->good())
|
||||||
{
|
{
|
||||||
Perr<< endl
|
Perr<< nl
|
||||||
<< "error::error(const dictionary& errDict) : "
|
<< "error::error(const dictionary& errDict) : "
|
||||||
"cannot open error stream"
|
"cannot open error stream"
|
||||||
<< endl;
|
<< endl;
|
||||||
@ -170,7 +170,7 @@ Foam::error::operator Foam::OSstream&()
|
|||||||
{
|
{
|
||||||
if (!messageStreamPtr_->good())
|
if (!messageStreamPtr_->good())
|
||||||
{
|
{
|
||||||
Perr<< endl
|
Perr<< nl
|
||||||
<< "error::operator OSstream&() : error stream has failed"
|
<< "error::operator OSstream&() : error stream has failed"
|
||||||
<< endl;
|
<< endl;
|
||||||
abort();
|
abort();
|
||||||
@ -223,8 +223,7 @@ void Foam::error::exit(const int errNo)
|
|||||||
{
|
{
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
else if (throwExceptions_)
|
||||||
if (throwExceptions_)
|
|
||||||
{
|
{
|
||||||
// Make a copy of the error to throw
|
// Make a copy of the error to throw
|
||||||
error errorException(*this);
|
error errorException(*this);
|
||||||
@ -236,13 +235,13 @@ void Foam::error::exit(const int errNo)
|
|||||||
}
|
}
|
||||||
else if (Pstream::parRun())
|
else if (Pstream::parRun())
|
||||||
{
|
{
|
||||||
Perr<< endl << *this << endl
|
Perr<< nl << *this << nl
|
||||||
<< "\nFOAM parallel run exiting\n" << endl;
|
<< "\nFOAM parallel run exiting\n" << endl;
|
||||||
Pstream::exit(errNo);
|
Pstream::exit(errNo);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Perr<< endl << *this << endl
|
Perr<< nl << *this << nl
|
||||||
<< "\nFOAM exiting\n" << endl;
|
<< "\nFOAM exiting\n" << endl;
|
||||||
std::exit(errNo);
|
std::exit(errNo);
|
||||||
}
|
}
|
||||||
@ -259,13 +258,12 @@ void Foam::error::abort()
|
|||||||
|
|
||||||
if (env("FOAM_ABORT"))
|
if (env("FOAM_ABORT"))
|
||||||
{
|
{
|
||||||
Perr<< endl << *this << endl
|
Perr<< nl << *this << nl
|
||||||
<< "\nFOAM aborting (FOAM_ABORT set)\n" << endl;
|
<< "\nFOAM aborting (FOAM_ABORT set)\n" << endl;
|
||||||
printStack(Perr);
|
printStack(Perr);
|
||||||
std::abort();
|
std::abort();
|
||||||
}
|
}
|
||||||
|
else if (throwExceptions_)
|
||||||
if (throwExceptions_)
|
|
||||||
{
|
{
|
||||||
// Make a copy of the error to throw
|
// Make a copy of the error to throw
|
||||||
error errorException(*this);
|
error errorException(*this);
|
||||||
@ -277,17 +275,22 @@ void Foam::error::abort()
|
|||||||
}
|
}
|
||||||
else if (Pstream::parRun())
|
else if (Pstream::parRun())
|
||||||
{
|
{
|
||||||
Perr<< endl << *this << endl
|
Perr<< nl << *this << nl
|
||||||
<< "\nFOAM parallel run aborting\n" << endl;
|
<< "\nFOAM parallel run aborting\n" << endl;
|
||||||
printStack(Perr);
|
printStack(Perr);
|
||||||
Pstream::abort();
|
Pstream::abort();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Perr<< endl << *this << endl
|
Perr<< nl << *this << nl
|
||||||
<< "\nFOAM aborting\n" << endl;
|
<< "\nFOAM aborting\n" << endl;
|
||||||
printStack(Perr);
|
printStack(Perr);
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
std::exit(1); // Prefer exit() to avoid unnecessary warnings
|
||||||
|
#else
|
||||||
std::abort();
|
std::abort();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -297,14 +300,14 @@ void Foam::error::write(Ostream& os, const bool includeTitle) const
|
|||||||
os << nl;
|
os << nl;
|
||||||
if (includeTitle)
|
if (includeTitle)
|
||||||
{
|
{
|
||||||
os << title().c_str() << endl;
|
os << title().c_str() << nl;
|
||||||
}
|
}
|
||||||
os << message().c_str();
|
os << message().c_str();
|
||||||
|
|
||||||
if (error::level >= 2 && sourceFileLineNumber())
|
if (error::level >= 2 && sourceFileLineNumber())
|
||||||
{
|
{
|
||||||
os << nl << nl
|
os << nl << nl
|
||||||
<< " From function " << functionName().c_str() << endl
|
<< " From function " << functionName().c_str() << nl
|
||||||
<< " in file " << sourceFileName().c_str()
|
<< " in file " << sourceFileName().c_str()
|
||||||
<< " at line " << sourceFileLineNumber() << '.';
|
<< " at line " << sourceFileLineNumber() << '.';
|
||||||
}
|
}
|
||||||
|
|||||||
@ -57,11 +57,6 @@ SourceFiles
|
|||||||
namespace Foam
|
namespace Foam
|
||||||
{
|
{
|
||||||
|
|
||||||
// Forward declarations
|
|
||||||
class error;
|
|
||||||
Ostream& operator<<(Ostream& os, const error& err);
|
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*\
|
/*---------------------------------------------------------------------------*\
|
||||||
Class error Declaration
|
Class error Declaration
|
||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
@ -112,7 +107,7 @@ public:
|
|||||||
static void warnAboutAge(const char* what, const int version);
|
static void warnAboutAge(const char* what, const int version);
|
||||||
|
|
||||||
|
|
||||||
// Member functions
|
// Member Functions
|
||||||
|
|
||||||
string message() const;
|
string message() const;
|
||||||
|
|
||||||
@ -212,19 +207,9 @@ public:
|
|||||||
|
|
||||||
//- Print error message
|
//- Print error message
|
||||||
void write(Ostream& os, const bool includeTitle = true) const;
|
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
|
Class IOerror Declaration
|
||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
@ -328,14 +313,18 @@ public:
|
|||||||
|
|
||||||
//- Print error message
|
//- Print error message
|
||||||
void write(Ostream& os, const bool includeTitle = true) const;
|
void write(Ostream& os, const bool includeTitle = true) const;
|
||||||
|
|
||||||
|
|
||||||
// Ostream operator
|
|
||||||
|
|
||||||
friend Ostream& operator<<(Ostream& os, const IOerror& err);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
//- Ostream operator
|
||||||
|
Ostream& operator<<(Ostream& os, const error& err);
|
||||||
|
|
||||||
|
//- Ostream operator
|
||||||
|
Ostream& operator<<(Ostream& os, const IOerror& err);
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
// Global error declarations: defined in error.C
|
// Global error declarations: defined in error.C
|
||||||
|
|
||||||
|
|||||||
@ -123,7 +123,7 @@ inline void Foam::fileName::stripInvalid()
|
|||||||
std::cerr
|
std::cerr
|
||||||
<< " For debug level (= " << debug
|
<< " For debug level (= " << debug
|
||||||
<< ") > 1 this is considered fatal" << std::endl;
|
<< ") > 1 this is considered fatal" << std::endl;
|
||||||
std::abort();
|
std::exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
removeRepeated('/');
|
removeRepeated('/');
|
||||||
|
|||||||
@ -155,7 +155,7 @@ inline void Foam::word::stripInvalid()
|
|||||||
std::cerr
|
std::cerr
|
||||||
<< " For debug level (= " << debug
|
<< " For debug level (= " << debug
|
||||||
<< ") > 1 this is considered fatal" << std::endl;
|
<< ") > 1 this is considered fatal" << std::endl;
|
||||||
std::abort();
|
std::exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -33,6 +33,7 @@ License
|
|||||||
void Foam::UPstream::addValidParOptions(HashTable<string>& validParOptions)
|
void Foam::UPstream::addValidParOptions(HashTable<string>& validParOptions)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
bool Foam::UPstream::initNull()
|
bool Foam::UPstream::initNull()
|
||||||
{
|
{
|
||||||
WarningInFunction
|
WarningInFunction
|
||||||
|
|||||||
Reference in New Issue
Block a user