1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software; you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
28 #include "OStringStream.H"
30 #include "dictionary.H"
34 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
36 Foam::IOerror::IOerror(const string& title)
39 ioFileName_("unknown"),
40 ioStartLineNumber_(-1),
45 Foam::IOerror::IOerror(const dictionary& errDict)
48 ioFileName_(errDict.lookup("ioFileName")),
49 ioStartLineNumber_(readLabel(errDict.lookup("ioStartLineNumber"))),
50 ioEndLineNumber_(readLabel(errDict.lookup("ioEndLineNumber")))
54 Foam::IOerror::~IOerror() throw()
58 Foam::OSstream& Foam::IOerror::operator()
60 const char* functionName,
61 const char* sourceFileName,
62 const int sourceFileLineNumber,
63 const string& ioFileName,
64 const label ioStartLineNumber,
65 const label ioEndLineNumber
68 error::operator()(functionName, sourceFileName, sourceFileLineNumber);
69 ioFileName_ = ioFileName;
70 ioStartLineNumber_ = ioStartLineNumber;
71 ioEndLineNumber_ = ioEndLineNumber;
73 return operator OSstream&();
77 Foam::OSstream& Foam::IOerror::operator()
79 const char* functionName,
80 const char* sourceFileName,
81 const int sourceFileLineNumber,
82 const IOstream& ioStream
91 ioStream.lineNumber(),
97 Foam::OSstream& Foam::IOerror::operator()
99 const char* functionName,
100 const char* sourceFileName,
101 const int sourceFileLineNumber,
102 const dictionary& dict
109 sourceFileLineNumber,
111 dict.startLineNumber(),
117 Foam::IOerror::operator Foam::dictionary() const
119 dictionary errDict(error::operator dictionary());
121 errDict.remove("type");
122 errDict.add("type", word("Foam::IOerror"));
124 errDict.add("ioFileName", ioFileName());
125 errDict.add("ioStartLineNumber", ioStartLineNumber());
126 errDict.add("ioEndLineNumber", ioEndLineNumber());
132 void Foam::IOerror::exit(const int)
134 if (!throwExceptions_ && JobInfo::constructed)
136 jobInfo.add("FatalIOError", operator dictionary());
142 Perr<< endl << *this << endl
143 << "\nFOAM aborting (FOAM_ABORT set)\n" << endl;
148 if (Pstream::parRun())
150 Perr<< endl << *this << endl
151 << "\nFOAM parallel run exiting\n" << endl;
156 if (throwExceptions_)
162 Perr<< endl << *this << endl
163 << "\nFOAM exiting\n" << endl;
170 void Foam::IOerror::abort()
172 if (!throwExceptions_ && JobInfo::constructed)
174 jobInfo.add("FatalIOError", operator dictionary());
180 Perr<< endl << *this << endl
181 << "\nFOAM aborting (FOAM_ABORT set)\n" << endl;
186 if (Pstream::parRun())
188 Perr<< endl << *this << endl
189 << "\nFOAM parallel run aborting\n" << endl;
195 if (throwExceptions_)
201 Perr<< endl << *this << endl
202 << "\nFOAM aborting\n" << endl;
210 Foam::Ostream& Foam::operator<<(Ostream& os, const IOerror& ioErr)
212 os << endl << ioErr.message().c_str() << endl << endl;
214 os << "file: " << ioErr.ioFileName().c_str();
216 if (ioErr.ioStartLineNumber() >= 0 && ioErr.ioEndLineNumber() >= 0)
218 os << " from line " << ioErr.ioStartLineNumber()
219 << " to line " << ioErr.ioEndLineNumber() << '.';
221 else if (ioErr.ioStartLineNumber() >= 0)
223 os << " at line " << ioErr.ioStartLineNumber() << '.';
226 if (IOerror::level >= 2 && ioErr.sourceFileLineNumber())
229 << " From function " << ioErr.functionName().c_str() << endl
230 << " in file " << ioErr.sourceFileName().c_str()
231 << " at line " << ioErr.sourceFileLineNumber() << '.';
238 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
239 // Global error definitions
241 Foam::IOerror Foam::FatalIOError("--> FOAM FATAL IO ERROR : ");
243 // ************************************************************************* //