diff --git a/src/OpenFOAM/db/error/IOerror.C b/src/OpenFOAM/db/error/IOerror.C index d3b51b3e7175bb9052a651f07be9a7e6e6ffa808..3b52d33293f3f791eeb36af7d7fe64c073098f61 100644 --- a/src/OpenFOAM/db/error/IOerror.C +++ b/src/OpenFOAM/db/error/IOerror.C @@ -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); diff --git a/src/OpenFOAM/db/error/error.C b/src/OpenFOAM/db/error/error.C index c143fcf5f14d6de000f34d3b2841c9a76e65a849..6c24ba4d886a1f856537544c18e225b4020aee45 100644 --- a/src/OpenFOAM/db/error/error.C +++ b/src/OpenFOAM/db/error/error.C @@ -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() << '.'; } diff --git a/src/OpenFOAM/db/error/error.H b/src/OpenFOAM/db/error/error.H index 0b191fee0ccfe522ce1918f4a9abc03b90982456..beb029db2fb0ca93e3f9c1cf4bd651f267a64f89 100644 --- a/src/OpenFOAM/db/error/error.H +++ b/src/OpenFOAM/db/error/error.H @@ -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); // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/OpenFOAM/primitives/strings/fileName/fileNameI.H b/src/OpenFOAM/primitives/strings/fileName/fileNameI.H index 4aa86b87d4c156c49cf9ee1d7a0e445a8655646e..9990cd5ed4a56bd9eafcdabb594259846e48f740 100644 --- a/src/OpenFOAM/primitives/strings/fileName/fileNameI.H +++ b/src/OpenFOAM/primitives/strings/fileName/fileNameI.H @@ -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('/'); diff --git a/src/OpenFOAM/primitives/strings/word/wordI.H b/src/OpenFOAM/primitives/strings/word/wordI.H index c5749eb50eb5aa005b06ad7ef0ea2daa0adc089f..825581a3bd2aa1eafd9569ecc119671c21981058 100644 --- a/src/OpenFOAM/primitives/strings/word/wordI.H +++ b/src/OpenFOAM/primitives/strings/word/wordI.H @@ -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); } } } diff --git a/src/Pstream/dummy/UPstream.C b/src/Pstream/dummy/UPstream.C index a41113ac4fefd76fbf7d50b275fb28a3cca816a6..67d4596ea26630bf977171bfead489adf2c744e3 100644 --- a/src/Pstream/dummy/UPstream.C +++ b/src/Pstream/dummy/UPstream.C @@ -33,6 +33,7 @@ License void Foam::UPstream::addValidParOptions(HashTable<string>& validParOptions) {} + bool Foam::UPstream::initNull() { WarningInFunction