STYLE: use const reference for caught exceptions

This commit is contained in:
Mark Olesen
2019-01-23 09:03:06 +01:00
parent a50c446853
commit a5cc0ffcad
20 changed files with 54 additions and 55 deletions

View File

@ -183,7 +183,7 @@ int main(int argc, char *argv[])
<< "(non-const)\n"; << "(non-const)\n";
} }
} }
catch (Foam::error& err) catch (const Foam::error& err)
{ {
Info<< "Failed (expected) " << err << nl << endl; Info<< "Failed (expected) " << err << nl << endl;
} }
@ -205,7 +205,7 @@ int main(int argc, char *argv[])
Info<< "[20] is false, as expected for const-access\n"; Info<< "[20] is false, as expected for const-access\n";
} }
} }
catch (Foam::error& err) catch (const Foam::error& err)
{ {
Info<< "Failed (expected) " << err << nl << endl; Info<< "Failed (expected) " << err << nl << endl;
} }
@ -275,7 +275,7 @@ int main(int argc, char *argv[])
list1[16] = 5; list1[16] = 5;
list1[36] = list1.max_value; list1[36] = list1.max_value;
} }
catch (Foam::error& err) catch (const Foam::error& err)
{ {
Info<< "Failed (expected) " << err << nl << endl; Info<< "Failed (expected) " << err << nl << endl;

View File

@ -201,7 +201,7 @@ int main(int argc, char *argv[])
Info<<"Random position(10,5): " Info<<"Random position(10,5): "
<< Random().position<label>(10, 5) << endl; << Random().position<label>(10, 5) << endl;
} }
catch (Foam::error& err) catch (const Foam::error& err)
{ {
Info<< "Caught FatalError " << err << nl << endl; Info<< "Caught FatalError " << err << nl << endl;
} }

View File

@ -108,11 +108,11 @@ void doTest(const dictionary& dict)
basicTests(cs1); basicTests(cs1);
} }
catch (Foam::IOerror& err) catch (const Foam::IOerror& err)
{ {
Info<< "Caught FatalIOError " << err << nl << endl; Info<< "Caught FatalIOError " << err << nl << endl;
} }
catch (Foam::error& err) catch (const Foam::error& err)
{ {
Info<< "Caught FatalError " << err << nl << endl; Info<< "Caught FatalError " << err << nl << endl;
} }
@ -136,11 +136,11 @@ void doTest(const objectRegistry& obr, const dictionary& dict)
basicTests(cs1); basicTests(cs1);
} }
catch (Foam::IOerror& err) catch (const Foam::IOerror& err)
{ {
Info<< "Caught FatalIOError " << err << nl << endl; Info<< "Caught FatalIOError " << err << nl << endl;
} }
catch (Foam::error& err) catch (const Foam::error& err)
{ {
Info<< "Caught FatalError " << err << nl << endl; Info<< "Caught FatalError " << err << nl << endl;
} }

View File

@ -61,12 +61,12 @@ scalar try_readScalar(const dictionary& dict, const word& k)
val = readScalar(dict.lookup(k)); val = readScalar(dict.lookup(k));
Info<< "readScalar(" << k << ") = " << val << nl; Info<< "readScalar(" << k << ") = " << val << nl;
} }
catch (Foam::IOerror& err) catch (const Foam::IOerror& err)
{ {
Info<< "readScalar(" << k << ") Caught FatalIOError " Info<< "readScalar(" << k << ") Caught FatalIOError "
<< err << nl << endl; << err << nl << endl;
} }
catch (Foam::error& err) catch (const Foam::error& err)
{ {
Info<< "readScalar(" << k << ") Caught FatalError " Info<< "readScalar(" << k << ") Caught FatalError "
<< err << nl << endl; << err << nl << endl;
@ -91,12 +91,12 @@ scalar try_getScalar(const dictionary& dict, const word& k)
val = dict.get<scalar>(k); val = dict.get<scalar>(k);
Info<< "get<scalar>(" << k << ") = " << val << nl; Info<< "get<scalar>(" << k << ") = " << val << nl;
} }
catch (Foam::IOerror& err) catch (const Foam::IOerror& err)
{ {
Info<< "get<scalar>(" << k << ") Caught FatalIOError " Info<< "get<scalar>(" << k << ") Caught FatalIOError "
<< err << nl << endl; << err << nl << endl;
} }
catch (Foam::error& err) catch (const Foam::error& err)
{ {
Info<< "get<scalar>(" << k << ") Caught FatalError " Info<< "get<scalar>(" << k << ") Caught FatalError "
<< err << nl << endl; << err << nl << endl;
@ -127,12 +127,12 @@ scalar try_getScalar(const entry* eptr, const word& k)
val = eptr->get<scalar>(); val = eptr->get<scalar>();
Info<< "entry get<scalar>(" << k << ") = " << val << nl; Info<< "entry get<scalar>(" << k << ") = " << val << nl;
} }
catch (Foam::IOerror& err) catch (const Foam::IOerror& err)
{ {
Info<< "entry get<scalar>(" << k << ") Caught FatalIOError " Info<< "entry get<scalar>(" << k << ") Caught FatalIOError "
<< err << nl << endl; << err << nl << endl;
} }
catch (Foam::error& err) catch (const Foam::error& err)
{ {
Info<< "entry get<scalar>(" << k << ") Caught FatalError " Info<< "entry get<scalar>(" << k << ") Caught FatalError "
<< err << nl << endl; << err << nl << endl;

View File

@ -112,7 +112,7 @@ unsigned checkDimensions
clip(a, b); clip(a, b);
dimsOk = true; dimsOk = true;
} }
catch (Foam::error& err) catch (const Foam::error& err)
{ {
errMsg = err.message(); errMsg = err.message();
} }

View File

@ -55,7 +55,7 @@ int main(int argc, char *argv[])
<< "Error 2" << "Error 2"
<< exit(FatalError); << exit(FatalError);
} }
catch (Foam::error& fErr) catch (const Foam::error& fErr)
{ {
Serr<< "Caught Foam error " << fErr << nl << endl; Serr<< "Caught Foam error " << fErr << nl << endl;
} }
@ -66,7 +66,7 @@ int main(int argc, char *argv[])
<< "Error# 3" << "Error# 3"
<< exit(FatalError); << exit(FatalError);
} }
catch (Foam::error& fErr) catch (const Foam::error& fErr)
{ {
Serr<< "Caught Foam error " << fErr << nl << endl; Serr<< "Caught Foam error " << fErr << nl << endl;
} }

View File

@ -120,7 +120,7 @@ int main(int argc, char *argv[])
labelledTri l1{ 1, 2, 3, 10, 24 }; labelledTri l1{ 1, 2, 3, 10, 24 };
Info<< "labelled:" << l1 << nl; Info<< "labelled:" << l1 << nl;
} }
catch (Foam::error& err) catch (const Foam::error& err)
{ {
WarningInFunction WarningInFunction
<< "Caught FatalError " << err << nl << endl; << "Caught FatalError " << err << nl << endl;

View File

@ -783,7 +783,7 @@ int main(int argc, char *argv[])
<< findEtcFile("<very-badName>", true) << nl << findEtcFile("<very-badName>", true) << nl
<< endl; << endl;
} }
catch (Foam::error& err) catch (const Foam::error& err)
{ {
Info<< nl << "findEtcFile() Caught FatalError " Info<< nl << "findEtcFile() Caught FatalError "
<< err << nl << endl; << err << nl << endl;

View File

@ -107,7 +107,7 @@ unsigned testParsing
result.second = function (test.second); result.second = function (test.second);
result.first = true; result.first = true;
} }
catch (Foam::error& err) catch (const Foam::error& err)
{ {
errMsg = err.message(); errMsg = err.message();
} }

View File

@ -127,7 +127,7 @@ int main(int argc, char *argv[])
} }
Info<< endl; Info<< endl;
} }
catch (Foam::error& err) catch (const Foam::error& err)
{ {
Info<< "Caught FatalError " << err << nl << endl; Info<< "Caught FatalError " << err << nl << endl;
continue; continue;
@ -164,7 +164,7 @@ int main(int argc, char *argv[])
Info<< "pass - null pointer is no expression" << endl; Info<< "pass - null pointer is no expression" << endl;
} }
} }
catch (Foam::error& err) catch (const Foam::error& err)
{ {
Info<< "Caught FatalError " << err << nl << endl; Info<< "Caught FatalError " << err << nl << endl;
} }
@ -181,7 +181,7 @@ int main(int argc, char *argv[])
Info<< "no match" << endl; Info<< "no match" << endl;
} }
} }
catch (Foam::error& err) catch (const Foam::error& err)
{ {
Info<< "Caught FatalError " << err << nl << endl; Info<< "Caught FatalError " << err << nl << endl;
} }
@ -198,7 +198,7 @@ int main(int argc, char *argv[])
Info<< "no match" << endl; Info<< "no match" << endl;
} }
} }
catch (Foam::error& err) catch (const Foam::error& err)
{ {
Info<< "Caught FatalError " << err << nl << endl; Info<< "Caught FatalError " << err << nl << endl;
} }
@ -215,7 +215,7 @@ int main(int argc, char *argv[])
Info<< "no match" << endl; Info<< "no match" << endl;
} }
} }
catch (Foam::error& err) catch (const Foam::error& err)
{ {
Info<< "Caught FatalError " << err << nl << endl; Info<< "Caught FatalError " << err << nl << endl;
} }
@ -232,7 +232,7 @@ int main(int argc, char *argv[])
Info<< "pass - no match on empty expression" << endl; Info<< "pass - no match on empty expression" << endl;
} }
} }
catch (Foam::error& err) catch (const Foam::error& err)
{ {
Info<< "Caught FatalError " << err << nl << endl; Info<< "Caught FatalError " << err << nl << endl;
} }
@ -249,7 +249,7 @@ int main(int argc, char *argv[])
Info<< "pass - no match on empty expression" << endl; Info<< "pass - no match on empty expression" << endl;
} }
} }
catch (Foam::error& err) catch (const Foam::error& err)
{ {
Info<< "Caught FatalError " << err << nl << endl; Info<< "Caught FatalError " << err << nl << endl;
} }

View File

@ -525,7 +525,7 @@ bool doCommand
} }
} }
} }
catch (Foam::IOerror& fIOErr) catch (const Foam::IOerror& fIOErr)
{ {
ok = false; ok = false;
@ -536,7 +536,7 @@ bool doCommand
Pout<< topoSetSource::usage(sourceType).c_str(); Pout<< topoSetSource::usage(sourceType).c_str();
} }
} }
catch (Foam::error& fErr) catch (const Foam::error& fErr)
{ {
ok = false; ok = false;

View File

@ -65,7 +65,7 @@ int main(int argc, char *argv[])
{ {
utility.reset(helpType::New(utilityName)); utility.reset(helpType::New(utilityName));
} }
catch (Foam::error& err) catch (const Foam::error& err)
{ {
utility.clear(); utility.clear();

View File

@ -47,7 +47,7 @@ if (doFiniteArea)
{ {
faMeshPtr.reset(new faMesh(meshProxy.baseMesh())); faMeshPtr.reset(new faMesh(meshProxy.baseMesh()));
} }
catch (Foam::error& err) catch (const Foam::error& err)
{ {
faMeshPtr.clear(); faMeshPtr.clear();
} }

View File

@ -286,12 +286,12 @@ void Foam::vtkPVFoam::convertVolFields
// Convert // Convert
convertVolField(patchInterpList, fld); convertVolField(patchInterpList, fld);
} }
catch (Foam::IOerror& ioErr) catch (const Foam::IOerror& ioErr)
{ {
ioErr.write(Warning, false); ioErr.write(Warning, false);
Info<< nl << endl; Info<< nl << endl;
} }
catch (Foam::error& err) catch (const Foam::error& err)
{ {
// Bit of trickery to get the original message // Bit of trickery to get the original message
err.write(Warning, false); err.write(Warning, false);
@ -368,12 +368,12 @@ void Foam::vtkPVFoam::convertDimFields
convertVolField(patchInterpList, volFld); convertVolField(patchInterpList, volFld);
} }
catch (Foam::IOerror& ioErr) catch (const Foam::IOerror& ioErr)
{ {
ioErr.write(Warning, false); ioErr.write(Warning, false);
Info<< nl << endl; Info<< nl << endl;
} }
catch (Foam::error& err) catch (const Foam::error& err)
{ {
// Bit of trickery to get the original message // Bit of trickery to get the original message
err.write(Warning, false); err.write(Warning, false);
@ -496,12 +496,12 @@ void Foam::vtkPVFoam::convertAreaFields
dataset->GetCellData()->AddArray(cdata); dataset->GetCellData()->AddArray(cdata);
} }
} }
catch (Foam::IOerror& ioErr) catch (const Foam::IOerror& ioErr)
{ {
ioErr.write(Warning, false); ioErr.write(Warning, false);
Info<< nl << endl; Info<< nl << endl;
} }
catch (Foam::error& err) catch (const Foam::error& err)
{ {
// Bit of trickery to get the original message // Bit of trickery to get the original message
err.write(Warning, false); err.write(Warning, false);
@ -638,12 +638,12 @@ void Foam::vtkPVFoam::convertPointFields
dataset->GetPointData()->AddArray(pdata); dataset->GetPointData()->AddArray(pdata);
} }
} }
catch (Foam::IOerror& ioErr) catch (const Foam::IOerror& ioErr)
{ {
ioErr.write(Warning, false); ioErr.write(Warning, false);
Info<< nl << endl; Info<< nl << endl;
} }
catch (Foam::error& err) catch (const Foam::error& err)
{ {
// Bit of trickery to get the original message // Bit of trickery to get the original message
err.write(Warning, false); err.write(Warning, false);
@ -817,12 +817,12 @@ void Foam::vtkPVFoam::convertLagrangianFields
vtkmesh->GetCellData()->AddArray(data); vtkmesh->GetCellData()->AddArray(data);
vtkmesh->GetPointData()->AddArray(data); vtkmesh->GetPointData()->AddArray(data);
} }
catch (Foam::IOerror& ioErr) catch (const Foam::IOerror& ioErr)
{ {
ioErr.write(Warning, false); ioErr.write(Warning, false);
Info<< nl << endl; Info<< nl << endl;
} }
catch (Foam::error& err) catch (const Foam::error& err)
{ {
// Bit of trickery to get the original message // Bit of trickery to get the original message
err.write(Warning, false); err.write(Warning, false);

View File

@ -226,9 +226,9 @@ int main(int argc, char *argv[])
// Report to output (avoid overwriting values from simulation) // Report to output (avoid overwriting values from simulation)
profiling::print(Info); profiling::print(Info);
} }
catch (Foam::IOerror& err) catch (const Foam::IOerror& err)
{ {
Warning<< err << endl; Warning << err << endl;
} }
Info<< endl; Info<< endl;

View File

@ -141,10 +141,9 @@ Foam::IOobjectList::IOobjectList
// Use object with local scope and current instance (no searching) // Use object with local scope and current instance (no searching)
ok = objectPtr->typeHeaderOk<IOList<label>>(false, false); ok = objectPtr->typeHeaderOk<IOList<label>>(false, false);
} }
catch (Foam::IOerror& err) catch (const Foam::IOerror& err)
{ {
Warning Warning << err << nl << endl;
<< err << nl << endl;
} }
FatalIOError.throwExceptions(throwingIOerr); FatalIOError.throwExceptions(throwingIOerr);

View File

@ -170,7 +170,7 @@ void Foam::IFstream::rewind()
{ {
gzPtr = dynamic_cast<igzstream*>(allocatedPtr_); gzPtr = dynamic_cast<igzstream*>(allocatedPtr_);
} }
catch (std::bad_cast&) catch (const std::bad_cast&)
{ {
gzPtr = nullptr; gzPtr = nullptr;
} }

View File

@ -805,12 +805,12 @@ bool Foam::functionObjectList::read()
foPtr = functionObject::New(key, time_, dict); foPtr = functionObject::New(key, time_, dict);
} }
} }
catch (Foam::IOerror& ioErr) catch (const Foam::IOerror& ioErr)
{ {
Info<< ioErr << nl << endl; Info<< ioErr << nl << endl;
::exit(1); ::exit(1);
} }
catch (Foam::error& err) catch (const Foam::error& err)
{ {
// Bit of trickery to get the original message // Bit of trickery to get the original message
err.write(Warning, false); err.write(Warning, false);

View File

@ -149,7 +149,7 @@ if (argList::postProcess(argc, argv))
// Report to output (avoid overwriting values from simulation) // Report to output (avoid overwriting values from simulation)
profiling::print(Info); profiling::print(Info);
} }
catch (IOerror& err) catch (const IOerror& err)
{ {
Warning<< err << endl; Warning<< err << endl;
} }

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2018-2019 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -88,7 +88,7 @@ inline To& dynamicCast(From& r)
{ {
return dynamic_cast<To&>(r); return dynamic_cast<To&>(r);
} }
catch (std::bad_cast&) catch (const std::bad_cast&)
{ {
FatalErrorInFunction FatalErrorInFunction
<< "Attempt to cast type " << typeid(r).name() << "Attempt to cast type " << typeid(r).name()
@ -109,7 +109,7 @@ inline To& dynamicCast(From& r, const dictionary& d)
{ {
return dynamic_cast<To&>(r); return dynamic_cast<To&>(r);
} }
catch (std::bad_cast&) catch (const std::bad_cast&)
{ {
FatalIOErrorInFunction(d) FatalIOErrorInFunction(d)
<< "Attempt to cast type " << typeid(r).name() << "Attempt to cast type " << typeid(r).name()
@ -131,7 +131,7 @@ inline To& refCast(From& r)
{ {
return dynamic_cast<To&>(r); return dynamic_cast<To&>(r);
} }
catch (std::bad_cast&) catch (const std::bad_cast&)
{ {
FatalErrorInFunction FatalErrorInFunction
<< "Attempt to cast type " << r.type() << "Attempt to cast type " << r.type()
@ -153,7 +153,7 @@ inline To& refCast(From& r, const dictionary& d)
{ {
return dynamic_cast<To&>(r); return dynamic_cast<To&>(r);
} }
catch (std::bad_cast&) catch (const std::bad_cast&)
{ {
FatalIOErrorInFunction(d) FatalIOErrorInFunction(d)
<< "Attempt to cast type " << r.type() << "Attempt to cast type " << r.type()