Improved the error message buffering by rewinding when the error is throw rather

than when it is initialised.  This allows messages to be created and added to.
This commit is contained in:
henry
2009-09-17 15:10:07 +01:00
parent 9011070676
commit 1d1fd3a37c
3 changed files with 20 additions and 13 deletions

View File

@ -105,7 +105,6 @@ Foam::OSstream& Foam::error::operator()
const int sourceFileLineNumber const int sourceFileLineNumber
) )
{ {
messageStreamPtr_->rewind();
functionName_ = functionName; functionName_ = functionName;
sourceFileName_ = sourceFileName; sourceFileName_ = sourceFileName;
sourceFileLineNumber_ = sourceFileLineNumber; sourceFileLineNumber_ = sourceFileLineNumber;
@ -137,7 +136,6 @@ Foam::error::operator OSstream&()
Perr<< endl Perr<< endl
<< "error::operator OSstream&() : error stream has failed" << "error::operator OSstream&() : error stream has failed"
<< endl; << endl;
printStack(Perr);
abort(); abort();
} }
@ -178,9 +176,6 @@ void Foam::error::exit(const int errNo)
if (abort_) if (abort_)
{ {
printStack(*this);
Perr<< endl << *this << endl
<< "\nFOAM aborting (FOAM_ABORT set)\n" << endl;
abort(); abort();
} }
@ -194,7 +189,13 @@ void Foam::error::exit(const int errNo)
{ {
if (throwExceptions_) if (throwExceptions_)
{ {
throw *this; // Make a copy of the error to throw
error errorException(*this);
// Rewind the message buffer for the next error message
messageStreamPtr_->rewind();
throw errorException;
} }
else else
{ {
@ -216,30 +217,36 @@ void Foam::error::abort()
if (abort_) if (abort_)
{ {
printStack(*this);
Perr<< endl << *this << endl Perr<< endl << *this << endl
<< "\nFOAM aborting (FOAM_ABORT set)\n" << endl; << "\nFOAM aborting (FOAM_ABORT set)\n" << endl;
printStack(Perr);
::abort(); ::abort();
} }
if (Pstream::parRun()) if (Pstream::parRun())
{ {
printStack(*this);
Perr<< endl << *this << endl Perr<< endl << *this << endl
<< "\nFOAM parallel run aborting\n" << endl; << "\nFOAM parallel run aborting\n" << endl;
printStack(Perr);
Pstream::abort(); Pstream::abort();
} }
else else
{ {
if (throwExceptions_) if (throwExceptions_)
{ {
// Make a copy of the error to throw
error errorException(*this);
// Rewind the message buffer for the next error message
messageStreamPtr_->rewind();
throw *this; throw *this;
} }
else else
{ {
printStack(*this);
Perr<< endl << *this << endl Perr<< endl << *this << endl
<< "\nFOAM aborting\n" << endl; << "\nFOAM aborting\n" << endl;
printStack(Perr);
::abort(); ::abort();
} }
} }
@ -248,7 +255,9 @@ void Foam::error::abort()
Foam::Ostream& Foam::operator<<(Ostream& os, const error& fErr) Foam::Ostream& Foam::operator<<(Ostream& os, const error& fErr)
{ {
os << endl << fErr.message().c_str(); os << endl
<< fErr.title().c_str() << endl
<< fErr.message().c_str();
if (error::level >= 2 && fErr.sourceFileLineNumber()) if (error::level >= 2 && fErr.sourceFileLineNumber())
{ {

View File

@ -35,7 +35,6 @@ int Foam::messageStream::level(Foam::debug::debugSwitch("level", 2));
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Construct from components
Foam::messageStream::messageStream Foam::messageStream::messageStream
( (
const string& title, const string& title,
@ -50,7 +49,6 @@ Foam::messageStream::messageStream
{} {}
//- Construct from dictionary
Foam::messageStream::messageStream(const dictionary& dict) Foam::messageStream::messageStream(const dictionary& dict)
: :
title_(dict.lookup("title")), title_(dict.lookup("title")),

View File

@ -1,7 +1,7 @@
/*--------------------------------*- C++ -*----------------------------------*\ /*--------------------------------*- C++ -*----------------------------------*\
| ========= | | | ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: 1.6 | | \\ / O peration | Version: dev |
| \\ / A nd | Web: www.OpenFOAM.org | | \\ / A nd | Web: www.OpenFOAM.org |
| \\/ M anipulation | | | \\/ M anipulation | |
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/