Skip to content

Commit

Permalink
STYLE: Catch exceptions by _const_ reference
Browse files Browse the repository at this point in the history
Following C++ Core Guidelines, April 10, 2022, which says that it is "typically
better" to catch by const reference than to catch by non-const reference. At
https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#e15-throw-by-value-catch-exceptions-from-a-hierarchy-by-reference

Discussed at C++ Core Guidelines issue isocpp/CppCoreGuidelines#518 "Catch
exceptions by const reference?", from February 3, 2016.

find . -type f | egrep '\.[it]?(cc|hh|[ch](\+\+|pp?|xx)?)$' | fgrep -v ThirdParty |     xargs sed -r -i         -e 's/catch \((const )?/catch (const /g'         -e 's/catch \(const \.\.\.\)/catch (...)/g'
  • Loading branch information
hjmjohnson committed May 12, 2022
1 parent baa89e7 commit 903f926
Show file tree
Hide file tree
Showing 50 changed files with 141 additions and 141 deletions.
6 changes: 3 additions & 3 deletions Examples/ANTS.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ ANTSex(int argc, char * argv[])
{
registration->RunRegistration();
}
catch (std::exception const & e)
catch (const std::exception const & e)
{
std::cerr << "Exception caught in ANTS: " << std::endl << e.what() << std::endl;
return EXIT_FAILURE;
Expand Down Expand Up @@ -163,12 +163,12 @@ ANTS(std::vector<std::string> args, std::ostream * /*out_stream = nullptr*/)
{
dim = std::stoi(argv[1]);
}
catch (std::invalid_argument & itkNotUsed(e))
catch (const std::invalid_argument & itkNotUsed(e))
{
// if no conversion could be performed
// assume --help is requested
}
catch (std::out_of_range & itkNotUsed(e))
catch (const std::out_of_range & itkNotUsed(e))
{
// if the converted value would fall out of the range of the result type
// or if the underlying function (std::strtol or std::strtoull) sets errno
Expand Down
2 changes: 1 addition & 1 deletion Examples/ANTSUseDeformationFieldToGetAffineTransform.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ WriteAffineTransformFile(typename TransformType::Pointer & transform, const std:
{
transform_writer->Update();
}
catch (itk::ExceptionObject & itkNotUsed(err))
catch (const itk::ExceptionObject & itkNotUsed(err))
{
std::cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl
<< "Exception in writing transform file: " << std::endl
Expand Down
2 changes: 1 addition & 1 deletion Examples/ANTSUseLandmarkImagesToGetAffineTransform.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ WriteAffineTransformFile(typename TransformType::Pointer & transform, const std:
{
transform_writer->Update();
}
catch (itk::ExceptionObject & itkNotUsed(err))
catch (const itk::ExceptionObject & itkNotUsed(err))
{
std::cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl
<< "Exception in writing transform file: " << std::endl
Expand Down
2 changes: 1 addition & 1 deletion Examples/Atropos.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -994,7 +994,7 @@ AtroposSegmentation(itk::ants::CommandLineParser * parser)
// segmenter->DebugOn();
segmenter->Update();
}
catch (itk::ExceptionObject & exp)
catch (const itk::ExceptionObject & exp)
{
if (verbose)
{
Expand Down
2 changes: 1 addition & 1 deletion Examples/AverageTensorImages.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ AverageTensorImages(std::vector<std::string> args, std::ostream * /*out_stream =

return EXIT_SUCCESS;
}
catch (itk::ExceptionObject & err)
catch (const itk::ExceptionObject & err)
{
std::cerr << "ExceptionObject caught !" << std::endl;
std::cerr << err << std::endl;
Expand Down
2 changes: 1 addition & 1 deletion Examples/CheckTopology.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ GetLargestComponent(typename TImage::Pointer image)
{
relabel->Update();
}
catch (itk::ExceptionObject & excep)
catch (const itk::ExceptionObject & excep)
{
std::cerr << "Relabel: exception caught !" << std::endl;
std::cerr << excep << std::endl;
Expand Down
2 changes: 1 addition & 1 deletion Examples/ClusterImageStatistics.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ ClusterStatistics(unsigned int argc, char * argv[])
{
relabel->Update();
}
catch (itk::ExceptionObject & excep)
catch (const itk::ExceptionObject & excep)
{
std::cerr << "Relabel: exception caught !" << std::endl;
std::cerr << excep << std::endl;
Expand Down
6 changes: 3 additions & 3 deletions Examples/ConformalMapping.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ MapToSphere(typename TImage::Pointer image, int fixdir, float e)
{
meshSource->Update();
}
catch (itk::ExceptionObject & exp)
catch (const itk::ExceptionObject & exp)
{
std::cout << "Exception thrown during Update() " << std::endl;
std::cout << exp << std::endl;
Expand Down Expand Up @@ -981,7 +981,7 @@ ConformalMapping(std::vector<std::string> args, std::ostream * out_stream = null
{
readfilter->Update();
}
catch (itk::ExceptionObject & e)
catch (const itk::ExceptionObject & e)
{
std::cout << "Exception caught during reference file reading " << std::endl;
std::cout << e << std::endl;
Expand All @@ -1006,7 +1006,7 @@ ConformalMapping(std::vector<std::string> args, std::ostream * out_stream = null
{
readfilter->Update();
}
catch (itk::ExceptionObject & e)
catch (const itk::ExceptionObject & e)
{
std::cout << "Exception caught during reference file reading " << std::endl;
std::cout << e << std::endl;
Expand Down
2 changes: 1 addition & 1 deletion Examples/DenoiseImage.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ Denoise(itk::ants::CommandLineParser * parser)
// denoiser->DebugOn();
denoiser->Update();
}
catch (itk::ExceptionObject & e)
catch (const itk::ExceptionObject & e)
{
if (verbose)
{
Expand Down
4 changes: 2 additions & 2 deletions Examples/ImageCompare.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ RegressionTestImage(const char * testImageFilename,
{
baselineReader->UpdateLargestPossibleRegion();
}
catch (itk::ExceptionObject & e)
catch (const itk::ExceptionObject & e)
{
std::cout << "Exception detected while reading " << baselineImageFilename << " : " << e.GetDescription();
return 1000;
Expand All @@ -170,7 +170,7 @@ RegressionTestImage(const char * testImageFilename,
{
testReader->UpdateLargestPossibleRegion();
}
catch (itk::ExceptionObject & e)
catch (const itk::ExceptionObject & e)
{
std::cout << "Exception detected while reading " << testImageFilename << " : " << e.GetDescription() << std::endl;
return 1000;
Expand Down
32 changes: 16 additions & 16 deletions Examples/ImageMath_Templates.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ FrobeniusNormOfMatrixDifference(int argc, char * argv[])
{
transformReader1->Update();
}
catch (itk::ExceptionObject & /* excp */)
catch (const itk::ExceptionObject & /* excp */)
{
std::cout << "no transformation1 that can be read" << fn1 << std::endl;
return 0;
Expand All @@ -271,7 +271,7 @@ FrobeniusNormOfMatrixDifference(int argc, char * argv[])
{
transformReader2->Update();
}
catch (itk::ExceptionObject & /* excp */)
catch (const itk::ExceptionObject & /* excp */)
{
std::cout << "no transformation2 that can be read" << fn2 << std::endl;
return 0;
Expand Down Expand Up @@ -485,7 +485,7 @@ GetLargestComponent(int argc, char * argv[])
{
relabel->Update();
}
catch (itk::ExceptionObject & /* excep */)
catch (const itk::ExceptionObject & /* excep */)
{
// std::cout << "Relabel: exception caught !" << std::endl;
// std::cout << excep << std::endl;
Expand Down Expand Up @@ -603,7 +603,7 @@ ClusterThresholdVariate(int argc, char * argv[])
{
relabel->Update();
}
catch (itk::ExceptionObject & /* excep */)
catch (const itk::ExceptionObject & /* excep */)
{
// std::cout << "Relabel: exception caught !" << std::endl;
// std::cout << excep << std::endl;
Expand Down Expand Up @@ -2959,7 +2959,7 @@ SliceTimingCorrection(int argc, char * argv[])
{
filter->Update();
}
catch (itk::ExceptionObject & /* exp */)
catch (const itk::ExceptionObject & /* exp */)
{
// std::cout << "Exception caught!" << std::endl;
// std::cout << exp << std::endl;
Expand Down Expand Up @@ -3781,7 +3781,7 @@ TimeSeriesToMatrix(int argc, char * argv[])
{
writer->Write();
}
catch (itk::ExceptionObject & /* exp */)
catch (const itk::ExceptionObject & /* exp */)
{
// std::cout << "Exception caught!" << std::endl;
// std::cout << exp << std::endl;
Expand Down Expand Up @@ -4498,7 +4498,7 @@ CompCorrAuto(int argc, char * argv[])
{
writer->Write();
}
catch (itk::ExceptionObject & /* exp */)
catch (const itk::ExceptionObject & /* exp */)
{
// std::cout << "Exception caught!" << std::endl;
// std::cout << exp << std::endl;
Expand Down Expand Up @@ -4840,7 +4840,7 @@ ThreeTissueConfounds(int argc, char * argv[])
{
writer->Write();
}
catch (itk::ExceptionObject & /* exp */)
catch (const itk::ExceptionObject & /* exp */)
{
// std::cout << "Exception caught!" << std::endl;
// std::cout << exp << std::endl;
Expand Down Expand Up @@ -6222,7 +6222,7 @@ TensorFunctions(int argc, char * argv[])
{
whichvec = std::stoi(fn2.c_str());
}
catch (std::invalid_argument & itkNotUsed(e))
catch (const std::invalid_argument & itkNotUsed(e))
{
// arg is not whichvec
}
Expand Down Expand Up @@ -8680,7 +8680,7 @@ FillHoles(int argc, char * argv[])
{
relabel->Update();
}
catch (itk::ExceptionObject & /* excep */)
catch (const itk::ExceptionObject & /* excep */)
{
// std::cout << "Relabel: exception caught !" << std::endl;
// std::cout << excep << std::endl;
Expand Down Expand Up @@ -9903,7 +9903,7 @@ DiceAndMinDistSum(int argc, char * argv[])
{
OutputCSV->Write();
}
catch (itk::ExceptionObject & /* exp */)
catch (const itk::ExceptionObject & /* exp */)
{
// std::cout << "Exception caught!" << std::endl;
// std::cout << exp << std::endl;
Expand Down Expand Up @@ -9945,7 +9945,7 @@ DiceAndMinDistSum(int argc, char * argv[])
OutputCSV->Write();
// std::cout << "Output written to " << outname.c_str() << ".csv." << std::endl;
}
catch (itk::ExceptionObject & /* exp */)
catch (const itk::ExceptionObject & /* exp */)
{
// std::cout << "Exception caught!" << std::endl;
// std::cout << exp << std::endl;
Expand Down Expand Up @@ -11441,7 +11441,7 @@ ConvertImageSetToMatrix(unsigned int argc, char * argv[])
{
writer->Write();
}
catch (itk::ExceptionObject & /* exp */)
catch (const itk::ExceptionObject & /* exp */)
{
// std::cout << "Exception caught!" << std::endl;
// std::cout << exp << std::endl;
Expand Down Expand Up @@ -11577,7 +11577,7 @@ RandomlySampleImageSetToCSV(unsigned int argc, char * argv[])
{
writer->Write();
}
catch (itk::ExceptionObject & /* exp */)
catch (const itk::ExceptionObject & /* exp */)
{
// std::cout << "Exception caught!" << std::endl;
// std::cout << exp << std::endl;
Expand Down Expand Up @@ -11757,7 +11757,7 @@ ConvertImageSetToEigenvectors(unsigned int argc, char * argv[])
{
writer->Write();
}
catch (itk::ExceptionObject & /* exp */)
catch (const itk::ExceptionObject & /* exp */)
{
// std::cout << "Exception caught!" << std::endl;
// std::cout << exp << std::endl;
Expand All @@ -11782,7 +11782,7 @@ ConvertImageSetToEigenvectors(unsigned int argc, char * argv[])
{
writer->Write();
}
catch (itk::ExceptionObject & /* exp */)
catch (const itk::ExceptionObject & /* exp */)
{
// std::cout << "Exception caught!" << std::endl;
// std::cout << exp << std::endl;
Expand Down
2 changes: 1 addition & 1 deletion Examples/ImageSetStatistics.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ GetClusterStat(typename TImage::Pointer image,
{
relabel->Update();
}
catch (itk::ExceptionObject & excep)
catch (const itk::ExceptionObject & excep)
{
std::cout << "Relabel: exception caught !" << std::endl;
std::cout << excep << std::endl;
Expand Down
2 changes: 1 addition & 1 deletion Examples/KellyKapowski.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ DiReCT(itk::ants::CommandLineParser * parser)
{
direct->Update(); // causes problems with ANTsR , unknown reason
}
catch (itk::ExceptionObject & e)
catch (const itk::ExceptionObject & e)
{
if (verbose)
{
Expand Down
2 changes: 1 addition & 1 deletion Examples/LabelClustersUniquely.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ LabelUniquely(int argc, char * argv[])
{
relabel->Update();
}
catch (itk::ExceptionObject & excep)
catch (const itk::ExceptionObject & excep)
{
std::cout << "Relabel: exception caught !" << std::endl;
std::cout << excep << std::endl;
Expand Down
2 changes: 1 addition & 1 deletion Examples/LabelGeometryMeasures.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ LabelGeometryMeasures(int argc, char * argv[])
{
writer->Write();
}
catch (itk::ExceptionObject & exp)
catch (const itk::ExceptionObject & exp)
{
std::cerr << "Exception caught!" << std::endl;
std::cerr << exp << std::endl;
Expand Down
2 changes: 1 addition & 1 deletion Examples/LabelOverlapMeasures.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ LabelOverlapMeasures(int argc, char * argv[])
{
writer->Write();
}
catch (itk::ExceptionObject & exp)
catch (const itk::ExceptionObject & exp)
{
std::cerr << "Exception caught!" << std::endl;
std::cerr << exp << std::endl;
Expand Down
6 changes: 3 additions & 3 deletions Examples/LesionFilling.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ LesionFilling(int argc, char * argv[])
{
LesionReader->Update();
}
catch (itk::ExceptionObject & itkNotUsed(excp))
catch (const itk::ExceptionObject & itkNotUsed(excp))
{
std::cout << "no lesion mask that can be read" << std::endl;
return 0;
Expand All @@ -64,7 +64,7 @@ LesionFilling(int argc, char * argv[])
{
T1Reader->Update();
}
catch (itk::ExceptionObject & itkNotUsed(excp))
catch (const itk::ExceptionObject & itkNotUsed(excp))
{
std::cout << "no T1 image that can be read" << std::endl;
return 0;
Expand Down Expand Up @@ -222,7 +222,7 @@ LesionFilling(int argc, char * argv[])
{
writer->Update();
}
catch (itk::ExceptionObject & err)
catch (const itk::ExceptionObject & err)
{
std::cerr << "ExceptionObject caught !" << std::endl;
std::cerr << err << std::endl;
Expand Down
2 changes: 1 addition & 1 deletion Examples/N3BiasFieldCorrection.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ N3(itk::ants::CommandLineParser * parser)
// correcter->DebugOn();
correcter->Update();
}
catch (itk::ExceptionObject & e)
catch (const itk::ExceptionObject & e)
{
if (verbose)
{
Expand Down
2 changes: 1 addition & 1 deletion Examples/N4BiasFieldCorrection.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ N4(itk::ants::CommandLineParser * parser)
// correcter->DebugOn();
correcter->Update();
}
catch (itk::ExceptionObject & e)
catch (const itk::ExceptionObject & e)
{
if (verbose)
{
Expand Down
2 changes: 1 addition & 1 deletion Examples/NonLocalSuperResolution.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ NonLocalSuperResolution(itk::ants::CommandLineParser * parser)
// superresoluter->DebugOn();
superresoluter->Update();
}
catch (itk::ExceptionObject & e)
catch (const itk::ExceptionObject & e)
{
if (verbose)
{
Expand Down
Loading

0 comments on commit 903f926

Please sign in to comment.