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
)
{
messageStreamPtr_->rewind();
functionName_ = functionName;
sourceFileName_ = sourceFileName;
sourceFileLineNumber_ = sourceFileLineNumber;
@ -137,7 +136,6 @@ Foam::error::operator OSstream&()
Perr<< endl
<< "error::operator OSstream&() : error stream has failed"
<< endl;
printStack(Perr);
abort();
}
@ -178,9 +176,6 @@ void Foam::error::exit(const int errNo)
if (abort_)
{
printStack(*this);
Perr<< endl << *this << endl
<< "\nFOAM aborting (FOAM_ABORT set)\n" << endl;
abort();
}
@ -194,7 +189,13 @@ void Foam::error::exit(const int errNo)
{
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
{
@ -216,30 +217,36 @@ void Foam::error::abort()
if (abort_)
{
printStack(*this);
Perr<< endl << *this << endl
<< "\nFOAM aborting (FOAM_ABORT set)\n" << endl;
printStack(Perr);
::abort();
}
if (Pstream::parRun())
{
printStack(*this);
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
error errorException(*this);
// Rewind the message buffer for the next error message
messageStreamPtr_->rewind();
throw *this;
}
else
{
printStack(*this);
Perr<< endl << *this << endl
<< "\nFOAM aborting\n" << endl;
printStack(Perr);
::abort();
}
}
@ -248,7 +255,9 @@ void Foam::error::abort()
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())
{

View File

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

View File

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