Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

STYLE: Catch exceptions by _const_ reference #1361

Merged
merged 1 commit into from
May 23, 2022

Conversation

hjmjohnson
Copy link
Collaborator

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?)$' | fgrep -v ThirdParty | xargs sed -r -i -e 's/catch ((const )?/catch (const /g' -e 's/catch (const ...)/catch (...)/g'

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'
@ntustison
Copy link
Member

Awesome. Thanks @hjmjohnson

@cookpa
Copy link
Member

cookpa commented May 13, 2022

Looks like an extra const somewhere, I'll check this out and try to fix the other warning I introduced to antsMotionCorr

@@ -87,7 +87,7 @@ ANTSex(int argc, char * argv[])
{
registration->RunRegistration();
}
catch (std::exception const & e)
catch (const std::exception const & e)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like the only error

@cookpa
Copy link
Member

cookpa commented May 13, 2022

Sorry @hjmjohnson I might be doing something wrong or you didn't check the "allow edits by maintainers" box on the PR, but I can't seem to push to this. But I did compile so the extra "const" in ANTS.cxx is the only thing preventing the build.

@cookpa cookpa changed the base branch from master to constExceptions May 23, 2022 23:51
@cookpa
Copy link
Member

cookpa commented May 23, 2022

Going to merge and make that one fix

@cookpa cookpa merged commit 7b8e8ab into ANTsX:constExceptions May 23, 2022
@cookpa cookpa mentioned this pull request May 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants