From a79d2835f1fb2c9226f7dfa58e5cfcf0e29d00fa Mon Sep 17 00:00:00 2001 From: mattijs Date: Mon, 30 Oct 2017 11:43:12 +0000 Subject: [PATCH] ENH: functionObjectList: format errors from FO reading. Fixes #575. --- src/OpenFOAM/db/error/error.C | 31 ++++++++++++------- src/OpenFOAM/db/error/error.H | 3 ++ .../functionObjectList/functionObjectList.C | 5 +-- 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/src/OpenFOAM/db/error/error.C b/src/OpenFOAM/db/error/error.C index b0c4b3d877..d72835e175 100644 --- a/src/OpenFOAM/db/error/error.C +++ b/src/OpenFOAM/db/error/error.C @@ -250,21 +250,30 @@ void Foam::error::abort() } +void Foam::error::write(Ostream& os, const bool includeTitle) const +{ + os << nl; + if (includeTitle) + { + os << title().c_str() << endl; + } + os << message().c_str(); + + if (error::level >= 2 && sourceFileLineNumber()) + { + os << nl << nl + << " From function " << functionName().c_str() << endl + << " in file " << sourceFileName().c_str() + << " at line " << sourceFileLineNumber() << '.'; + } +} + + // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * // Foam::Ostream& Foam::operator<<(Ostream& os, const error& err) { - os << nl - << err.title().c_str() << endl - << err.message().c_str(); - - if (error::level >= 2 && err.sourceFileLineNumber()) - { - os << nl << nl - << " From function " << err.functionName().c_str() << endl - << " in file " << err.sourceFileName().c_str() - << " at line " << err.sourceFileLineNumber() << '.'; - } + err.write(os); return os; } diff --git a/src/OpenFOAM/db/error/error.H b/src/OpenFOAM/db/error/error.H index 961bd3cd4d..bf59c5facb 100644 --- a/src/OpenFOAM/db/error/error.H +++ b/src/OpenFOAM/db/error/error.H @@ -195,6 +195,9 @@ public: // Prints stack before exiting. void abort(); + //- Print error message + void write(Ostream& os, const bool includeTitle = true) const; + // Ostream operator diff --git a/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.C b/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.C index 0acd4e17d1..0082266d5b 100644 --- a/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.C +++ b/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.C @@ -788,8 +788,9 @@ bool Foam::functionObjectList::read() } catch (Foam::error& err) { - WarningInFunction - << "Caught FatalError " << err << nl << endl; + // Bit of trickery to get the original message + err.write(Warning, false); + InfoInFunction << nl << endl; } // Restore previous exception throwing state