IOerror.C
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "error.H"
00028 #include "OStringStream.H"
00029 #include "fileName.H"
00030 #include "dictionary.H"
00031 #include "JobInfo.H"
00032 #include "Pstream.H"
00033
00034
00035
00036 Foam::IOerror::IOerror(const string& title)
00037 :
00038 error(title),
00039 ioFileName_("unknown"),
00040 ioStartLineNumber_(-1),
00041 ioEndLineNumber_(-1)
00042 {}
00043
00044
00045 Foam::IOerror::IOerror(const dictionary& errDict)
00046 :
00047 error(errDict),
00048 ioFileName_(errDict.lookup("ioFileName")),
00049 ioStartLineNumber_(readLabel(errDict.lookup("ioStartLineNumber"))),
00050 ioEndLineNumber_(readLabel(errDict.lookup("ioEndLineNumber")))
00051 {}
00052
00053
00054 Foam::IOerror::~IOerror() throw()
00055 {}
00056
00057
00058 Foam::OSstream& Foam::IOerror::operator()
00059 (
00060 const char* functionName,
00061 const char* sourceFileName,
00062 const int sourceFileLineNumber,
00063 const string& ioFileName,
00064 const label ioStartLineNumber,
00065 const label ioEndLineNumber
00066 )
00067 {
00068 error::operator()(functionName, sourceFileName, sourceFileLineNumber);
00069 ioFileName_ = ioFileName;
00070 ioStartLineNumber_ = ioStartLineNumber;
00071 ioEndLineNumber_ = ioEndLineNumber;
00072
00073 return operator OSstream&();
00074 }
00075
00076
00077 Foam::OSstream& Foam::IOerror::operator()
00078 (
00079 const char* functionName,
00080 const char* sourceFileName,
00081 const int sourceFileLineNumber,
00082 const IOstream& ioStream
00083 )
00084 {
00085 return operator()
00086 (
00087 functionName,
00088 sourceFileName,
00089 sourceFileLineNumber,
00090 ioStream.name(),
00091 ioStream.lineNumber(),
00092 -1
00093 );
00094 }
00095
00096
00097 Foam::OSstream& Foam::IOerror::operator()
00098 (
00099 const char* functionName,
00100 const char* sourceFileName,
00101 const int sourceFileLineNumber,
00102 const dictionary& dict
00103 )
00104 {
00105 return operator()
00106 (
00107 functionName,
00108 sourceFileName,
00109 sourceFileLineNumber,
00110 dict.name(),
00111 dict.startLineNumber(),
00112 dict.endLineNumber()
00113 );
00114 }
00115
00116
00117 Foam::IOerror::operator Foam::dictionary() const
00118 {
00119 dictionary errDict(error::operator dictionary());
00120
00121 errDict.remove("type");
00122 errDict.add("type", word("Foam::IOerror"));
00123
00124 errDict.add("ioFileName", ioFileName());
00125 errDict.add("ioStartLineNumber", ioStartLineNumber());
00126 errDict.add("ioEndLineNumber", ioEndLineNumber());
00127
00128 return errDict;
00129 }
00130
00131
00132 void Foam::IOerror::exit(const int)
00133 {
00134 if (!throwExceptions_ && JobInfo::constructed)
00135 {
00136 jobInfo.add("FatalIOError", operator dictionary());
00137 jobInfo.exit();
00138 }
00139
00140 if (abort_)
00141 {
00142 Perr<< endl << *this << endl
00143 << "\nFOAM aborting (FOAM_ABORT set)\n" << endl;
00144 printStack(Perr);
00145 ::abort();
00146 }
00147
00148 if (Pstream::parRun())
00149 {
00150 Perr<< endl << *this << endl
00151 << "\nFOAM parallel run exiting\n" << endl;
00152 Pstream::exit(1);
00153 }
00154 else
00155 {
00156 if (throwExceptions_)
00157 {
00158 throw *this;
00159 }
00160 else
00161 {
00162 Perr<< endl << *this << endl
00163 << "\nFOAM exiting\n" << endl;
00164 ::exit(1);
00165 }
00166 }
00167 }
00168
00169
00170 void Foam::IOerror::abort()
00171 {
00172 if (!throwExceptions_ && JobInfo::constructed)
00173 {
00174 jobInfo.add("FatalIOError", operator dictionary());
00175 jobInfo.abort();
00176 }
00177
00178 if (abort_)
00179 {
00180 Perr<< endl << *this << endl
00181 << "\nFOAM aborting (FOAM_ABORT set)\n" << endl;
00182 printStack(Perr);
00183 ::abort();
00184 }
00185
00186 if (Pstream::parRun())
00187 {
00188 Perr<< endl << *this << endl
00189 << "\nFOAM parallel run aborting\n" << endl;
00190 printStack(Perr);
00191 Pstream::abort();
00192 }
00193 else
00194 {
00195 if (throwExceptions_)
00196 {
00197 throw *this;
00198 }
00199 else
00200 {
00201 Perr<< endl << *this << endl
00202 << "\nFOAM aborting\n" << endl;
00203 printStack(Perr);
00204 ::abort();
00205 }
00206 }
00207 }
00208
00209
00210 Foam::Ostream& Foam::operator<<(Ostream& os, const IOerror& ioErr)
00211 {
00212 os << endl << ioErr.message().c_str() << endl << endl;
00213
00214 os << "file: " << ioErr.ioFileName().c_str();
00215
00216 if (ioErr.ioStartLineNumber() >= 0 && ioErr.ioEndLineNumber() >= 0)
00217 {
00218 os << " from line " << ioErr.ioStartLineNumber()
00219 << " to line " << ioErr.ioEndLineNumber() << '.';
00220 }
00221 else if (ioErr.ioStartLineNumber() >= 0)
00222 {
00223 os << " at line " << ioErr.ioStartLineNumber() << '.';
00224 }
00225
00226 if (IOerror::level >= 2 && ioErr.sourceFileLineNumber())
00227 {
00228 os << endl << endl
00229 << " From function " << ioErr.functionName().c_str() << endl
00230 << " in file " << ioErr.sourceFileName().c_str()
00231 << " at line " << ioErr.sourceFileLineNumber() << '.';
00232 }
00233
00234 return os;
00235 }
00236
00237
00238
00239
00240
00241 Foam::IOerror Foam::FatalIOError("--> FOAM FATAL IO ERROR : ");
00242
00243
Copyright © 2000-2009 OpenCFD Ltd