Skip to content

Commit 903f926

Browse files
committed
STYLE: Catch exceptions by _const_ reference
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'
1 parent baa89e7 commit 903f926

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+141
-141
lines changed

Examples/ANTS.cxx

+3-3
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ ANTSex(int argc, char * argv[])
8787
{
8888
registration->RunRegistration();
8989
}
90-
catch (std::exception const & e)
90+
catch (const std::exception const & e)
9191
{
9292
std::cerr << "Exception caught in ANTS: " << std::endl << e.what() << std::endl;
9393
return EXIT_FAILURE;
@@ -163,12 +163,12 @@ ANTS(std::vector<std::string> args, std::ostream * /*out_stream = nullptr*/)
163163
{
164164
dim = std::stoi(argv[1]);
165165
}
166-
catch (std::invalid_argument & itkNotUsed(e))
166+
catch (const std::invalid_argument & itkNotUsed(e))
167167
{
168168
// if no conversion could be performed
169169
// assume --help is requested
170170
}
171-
catch (std::out_of_range & itkNotUsed(e))
171+
catch (const std::out_of_range & itkNotUsed(e))
172172
{
173173
// if the converted value would fall out of the range of the result type
174174
// or if the underlying function (std::strtol or std::strtoull) sets errno

Examples/ANTSUseDeformationFieldToGetAffineTransform.cxx

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ WriteAffineTransformFile(typename TransformType::Pointer & transform, const std:
3939
{
4040
transform_writer->Update();
4141
}
42-
catch (itk::ExceptionObject & itkNotUsed(err))
42+
catch (const itk::ExceptionObject & itkNotUsed(err))
4343
{
4444
std::cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl
4545
<< "Exception in writing transform file: " << std::endl

Examples/ANTSUseLandmarkImagesToGetAffineTransform.cxx

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ WriteAffineTransformFile(typename TransformType::Pointer & transform, const std:
3636
{
3737
transform_writer->Update();
3838
}
39-
catch (itk::ExceptionObject & itkNotUsed(err))
39+
catch (const itk::ExceptionObject & itkNotUsed(err))
4040
{
4141
std::cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl
4242
<< "Exception in writing transform file: " << std::endl

Examples/Atropos.cxx

+1-1
Original file line numberDiff line numberDiff line change
@@ -994,7 +994,7 @@ AtroposSegmentation(itk::ants::CommandLineParser * parser)
994994
// segmenter->DebugOn();
995995
segmenter->Update();
996996
}
997-
catch (itk::ExceptionObject & exp)
997+
catch (const itk::ExceptionObject & exp)
998998
{
999999
if (verbose)
10001000
{

Examples/AverageTensorImages.cxx

+1-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ AverageTensorImages(std::vector<std::string> args, std::ostream * /*out_stream =
172172

173173
return EXIT_SUCCESS;
174174
}
175-
catch (itk::ExceptionObject & err)
175+
catch (const itk::ExceptionObject & err)
176176
{
177177
std::cerr << "ExceptionObject caught !" << std::endl;
178178
std::cerr << err << std::endl;

Examples/CheckTopology.cxx

+1-1
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ GetLargestComponent(typename TImage::Pointer image)
189189
{
190190
relabel->Update();
191191
}
192-
catch (itk::ExceptionObject & excep)
192+
catch (const itk::ExceptionObject & excep)
193193
{
194194
std::cerr << "Relabel: exception caught !" << std::endl;
195195
std::cerr << excep << std::endl;

Examples/ClusterImageStatistics.cxx

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ ClusterStatistics(unsigned int argc, char * argv[])
117117
{
118118
relabel->Update();
119119
}
120-
catch (itk::ExceptionObject & excep)
120+
catch (const itk::ExceptionObject & excep)
121121
{
122122
std::cerr << "Relabel: exception caught !" << std::endl;
123123
std::cerr << excep << std::endl;

Examples/ConformalMapping.cxx

+3-3
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ MapToSphere(typename TImage::Pointer image, int fixdir, float e)
190190
{
191191
meshSource->Update();
192192
}
193-
catch (itk::ExceptionObject & exp)
193+
catch (const itk::ExceptionObject & exp)
194194
{
195195
std::cout << "Exception thrown during Update() " << std::endl;
196196
std::cout << exp << std::endl;
@@ -981,7 +981,7 @@ ConformalMapping(std::vector<std::string> args, std::ostream * out_stream = null
981981
{
982982
readfilter->Update();
983983
}
984-
catch (itk::ExceptionObject & e)
984+
catch (const itk::ExceptionObject & e)
985985
{
986986
std::cout << "Exception caught during reference file reading " << std::endl;
987987
std::cout << e << std::endl;
@@ -1006,7 +1006,7 @@ ConformalMapping(std::vector<std::string> args, std::ostream * out_stream = null
10061006
{
10071007
readfilter->Update();
10081008
}
1009-
catch (itk::ExceptionObject & e)
1009+
catch (const itk::ExceptionObject & e)
10101010
{
10111011
std::cout << "Exception caught during reference file reading " << std::endl;
10121012
std::cout << e << std::endl;

Examples/DenoiseImage.cxx

+1-1
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ Denoise(itk::ants::CommandLineParser * parser)
294294
// denoiser->DebugOn();
295295
denoiser->Update();
296296
}
297-
catch (itk::ExceptionObject & e)
297+
catch (const itk::ExceptionObject & e)
298298
{
299299
if (verbose)
300300
{

Examples/ImageCompare.cxx

+2-2
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ RegressionTestImage(const char * testImageFilename,
157157
{
158158
baselineReader->UpdateLargestPossibleRegion();
159159
}
160-
catch (itk::ExceptionObject & e)
160+
catch (const itk::ExceptionObject & e)
161161
{
162162
std::cout << "Exception detected while reading " << baselineImageFilename << " : " << e.GetDescription();
163163
return 1000;
@@ -170,7 +170,7 @@ RegressionTestImage(const char * testImageFilename,
170170
{
171171
testReader->UpdateLargestPossibleRegion();
172172
}
173-
catch (itk::ExceptionObject & e)
173+
catch (const itk::ExceptionObject & e)
174174
{
175175
std::cout << "Exception detected while reading " << testImageFilename << " : " << e.GetDescription() << std::endl;
176176
return 1000;

Examples/ImageMath_Templates.hxx

+16-16
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ FrobeniusNormOfMatrixDifference(int argc, char * argv[])
260260
{
261261
transformReader1->Update();
262262
}
263-
catch (itk::ExceptionObject & /* excp */)
263+
catch (const itk::ExceptionObject & /* excp */)
264264
{
265265
std::cout << "no transformation1 that can be read" << fn1 << std::endl;
266266
return 0;
@@ -271,7 +271,7 @@ FrobeniusNormOfMatrixDifference(int argc, char * argv[])
271271
{
272272
transformReader2->Update();
273273
}
274-
catch (itk::ExceptionObject & /* excp */)
274+
catch (const itk::ExceptionObject & /* excp */)
275275
{
276276
std::cout << "no transformation2 that can be read" << fn2 << std::endl;
277277
return 0;
@@ -485,7 +485,7 @@ GetLargestComponent(int argc, char * argv[])
485485
{
486486
relabel->Update();
487487
}
488-
catch (itk::ExceptionObject & /* excep */)
488+
catch (const itk::ExceptionObject & /* excep */)
489489
{
490490
// std::cout << "Relabel: exception caught !" << std::endl;
491491
// std::cout << excep << std::endl;
@@ -603,7 +603,7 @@ ClusterThresholdVariate(int argc, char * argv[])
603603
{
604604
relabel->Update();
605605
}
606-
catch (itk::ExceptionObject & /* excep */)
606+
catch (const itk::ExceptionObject & /* excep */)
607607
{
608608
// std::cout << "Relabel: exception caught !" << std::endl;
609609
// std::cout << excep << std::endl;
@@ -2959,7 +2959,7 @@ SliceTimingCorrection(int argc, char * argv[])
29592959
{
29602960
filter->Update();
29612961
}
2962-
catch (itk::ExceptionObject & /* exp */)
2962+
catch (const itk::ExceptionObject & /* exp */)
29632963
{
29642964
// std::cout << "Exception caught!" << std::endl;
29652965
// std::cout << exp << std::endl;
@@ -3781,7 +3781,7 @@ TimeSeriesToMatrix(int argc, char * argv[])
37813781
{
37823782
writer->Write();
37833783
}
3784-
catch (itk::ExceptionObject & /* exp */)
3784+
catch (const itk::ExceptionObject & /* exp */)
37853785
{
37863786
// std::cout << "Exception caught!" << std::endl;
37873787
// std::cout << exp << std::endl;
@@ -4498,7 +4498,7 @@ CompCorrAuto(int argc, char * argv[])
44984498
{
44994499
writer->Write();
45004500
}
4501-
catch (itk::ExceptionObject & /* exp */)
4501+
catch (const itk::ExceptionObject & /* exp */)
45024502
{
45034503
// std::cout << "Exception caught!" << std::endl;
45044504
// std::cout << exp << std::endl;
@@ -4840,7 +4840,7 @@ ThreeTissueConfounds(int argc, char * argv[])
48404840
{
48414841
writer->Write();
48424842
}
4843-
catch (itk::ExceptionObject & /* exp */)
4843+
catch (const itk::ExceptionObject & /* exp */)
48444844
{
48454845
// std::cout << "Exception caught!" << std::endl;
48464846
// std::cout << exp << std::endl;
@@ -6222,7 +6222,7 @@ TensorFunctions(int argc, char * argv[])
62226222
{
62236223
whichvec = std::stoi(fn2.c_str());
62246224
}
6225-
catch (std::invalid_argument & itkNotUsed(e))
6225+
catch (const std::invalid_argument & itkNotUsed(e))
62266226
{
62276227
// arg is not whichvec
62286228
}
@@ -8680,7 +8680,7 @@ FillHoles(int argc, char * argv[])
86808680
{
86818681
relabel->Update();
86828682
}
8683-
catch (itk::ExceptionObject & /* excep */)
8683+
catch (const itk::ExceptionObject & /* excep */)
86848684
{
86858685
// std::cout << "Relabel: exception caught !" << std::endl;
86868686
// std::cout << excep << std::endl;
@@ -9903,7 +9903,7 @@ DiceAndMinDistSum(int argc, char * argv[])
99039903
{
99049904
OutputCSV->Write();
99059905
}
9906-
catch (itk::ExceptionObject & /* exp */)
9906+
catch (const itk::ExceptionObject & /* exp */)
99079907
{
99089908
// std::cout << "Exception caught!" << std::endl;
99099909
// std::cout << exp << std::endl;
@@ -9945,7 +9945,7 @@ DiceAndMinDistSum(int argc, char * argv[])
99459945
OutputCSV->Write();
99469946
// std::cout << "Output written to " << outname.c_str() << ".csv." << std::endl;
99479947
}
9948-
catch (itk::ExceptionObject & /* exp */)
9948+
catch (const itk::ExceptionObject & /* exp */)
99499949
{
99509950
// std::cout << "Exception caught!" << std::endl;
99519951
// std::cout << exp << std::endl;
@@ -11441,7 +11441,7 @@ ConvertImageSetToMatrix(unsigned int argc, char * argv[])
1144111441
{
1144211442
writer->Write();
1144311443
}
11444-
catch (itk::ExceptionObject & /* exp */)
11444+
catch (const itk::ExceptionObject & /* exp */)
1144511445
{
1144611446
// std::cout << "Exception caught!" << std::endl;
1144711447
// std::cout << exp << std::endl;
@@ -11577,7 +11577,7 @@ RandomlySampleImageSetToCSV(unsigned int argc, char * argv[])
1157711577
{
1157811578
writer->Write();
1157911579
}
11580-
catch (itk::ExceptionObject & /* exp */)
11580+
catch (const itk::ExceptionObject & /* exp */)
1158111581
{
1158211582
// std::cout << "Exception caught!" << std::endl;
1158311583
// std::cout << exp << std::endl;
@@ -11757,7 +11757,7 @@ ConvertImageSetToEigenvectors(unsigned int argc, char * argv[])
1175711757
{
1175811758
writer->Write();
1175911759
}
11760-
catch (itk::ExceptionObject & /* exp */)
11760+
catch (const itk::ExceptionObject & /* exp */)
1176111761
{
1176211762
// std::cout << "Exception caught!" << std::endl;
1176311763
// std::cout << exp << std::endl;
@@ -11782,7 +11782,7 @@ ConvertImageSetToEigenvectors(unsigned int argc, char * argv[])
1178211782
{
1178311783
writer->Write();
1178411784
}
11785-
catch (itk::ExceptionObject & /* exp */)
11785+
catch (const itk::ExceptionObject & /* exp */)
1178611786
{
1178711787
// std::cout << "Exception caught!" << std::endl;
1178811788
// std::cout << exp << std::endl;

Examples/ImageSetStatistics.cxx

+1-1
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ GetClusterStat(typename TImage::Pointer image,
284284
{
285285
relabel->Update();
286286
}
287-
catch (itk::ExceptionObject & excep)
287+
catch (const itk::ExceptionObject & excep)
288288
{
289289
std::cout << "Relabel: exception caught !" << std::endl;
290290
std::cout << excep << std::endl;

Examples/KellyKapowski.cxx

+1-1
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ DiReCT(itk::ants::CommandLineParser * parser)
372372
{
373373
direct->Update(); // causes problems with ANTsR , unknown reason
374374
}
375-
catch (itk::ExceptionObject & e)
375+
catch (const itk::ExceptionObject & e)
376376
{
377377
if (verbose)
378378
{

Examples/LabelClustersUniquely.cxx

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ LabelUniquely(int argc, char * argv[])
9999
{
100100
relabel->Update();
101101
}
102-
catch (itk::ExceptionObject & excep)
102+
catch (const itk::ExceptionObject & excep)
103103
{
104104
std::cout << "Relabel: exception caught !" << std::endl;
105105
std::cout << excep << std::endl;

Examples/LabelGeometryMeasures.cxx

+1-1
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ LabelGeometryMeasures(int argc, char * argv[])
230230
{
231231
writer->Write();
232232
}
233-
catch (itk::ExceptionObject & exp)
233+
catch (const itk::ExceptionObject & exp)
234234
{
235235
std::cerr << "Exception caught!" << std::endl;
236236
std::cerr << exp << std::endl;

Examples/LabelOverlapMeasures.cxx

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ LabelOverlapMeasures(int argc, char * argv[])
120120
{
121121
writer->Write();
122122
}
123-
catch (itk::ExceptionObject & exp)
123+
catch (const itk::ExceptionObject & exp)
124124
{
125125
std::cerr << "Exception caught!" << std::endl;
126126
std::cerr << exp << std::endl;

Examples/LesionFilling.cxx

+3-3
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ LesionFilling(int argc, char * argv[])
5353
{
5454
LesionReader->Update();
5555
}
56-
catch (itk::ExceptionObject & itkNotUsed(excp))
56+
catch (const itk::ExceptionObject & itkNotUsed(excp))
5757
{
5858
std::cout << "no lesion mask that can be read" << std::endl;
5959
return 0;
@@ -64,7 +64,7 @@ LesionFilling(int argc, char * argv[])
6464
{
6565
T1Reader->Update();
6666
}
67-
catch (itk::ExceptionObject & itkNotUsed(excp))
67+
catch (const itk::ExceptionObject & itkNotUsed(excp))
6868
{
6969
std::cout << "no T1 image that can be read" << std::endl;
7070
return 0;
@@ -222,7 +222,7 @@ LesionFilling(int argc, char * argv[])
222222
{
223223
writer->Update();
224224
}
225-
catch (itk::ExceptionObject & err)
225+
catch (const itk::ExceptionObject & err)
226226
{
227227
std::cerr << "ExceptionObject caught !" << std::endl;
228228
std::cerr << err << std::endl;

Examples/N3BiasFieldCorrection.cxx

+1-1
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ N3(itk::ants::CommandLineParser * parser)
550550
// correcter->DebugOn();
551551
correcter->Update();
552552
}
553-
catch (itk::ExceptionObject & e)
553+
catch (const itk::ExceptionObject & e)
554554
{
555555
if (verbose)
556556
{

Examples/N4BiasFieldCorrection.cxx

+1-1
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ N4(itk::ants::CommandLineParser * parser)
411411
// correcter->DebugOn();
412412
correcter->Update();
413413
}
414-
catch (itk::ExceptionObject & e)
414+
catch (const itk::ExceptionObject & e)
415415
{
416416
if (verbose)
417417
{

Examples/NonLocalSuperResolution.cxx

+1-1
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ NonLocalSuperResolution(itk::ants::CommandLineParser * parser)
353353
// superresoluter->DebugOn();
354354
superresoluter->Update();
355355
}
356-
catch (itk::ExceptionObject & e)
356+
catch (const itk::ExceptionObject & e)
357357
{
358358
if (verbose)
359359
{

0 commit comments

Comments
 (0)