-
-
Notifications
You must be signed in to change notification settings - Fork 665
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 #3419
STYLE: Catch exceptions by _const_ reference #3419
Conversation
For the record, this pull request was triggered by the discussion starting at #3339 (comment) |
Good idea! I change a few more when I use: cd git/ITK
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' Just in case the changes this makes aren't some that you have already considered and rejected ... running that after your commits and then running |
Replaced `catch \((\w+) &` with `catch (const $1 &`, using Visual Studio 2019, Find and Replace, Replace in Files, Use regular expressions. 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 With help from Lee Newberg.
d864f73
to
65ea925
Compare
Thanks @Leengit. Please check the force-push that I just did 😃 |
Love This! Minor request. Can the "xargs command" used be placed in the commit message? Even if it is not perfect, it's a great start when updating all the Remote modules. |
Text-wise, I see one more possibility (though perhaps it was rejected for other reasons):
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@Leengit Sorry the PR is merged already. Feel free to do a follow-up. But as far as I can see, it's the only case that still wasn't fixed with this PR. With this PR, I only looked for |
For the record, this pull request appears to be a follow-up to pull request #1492 "COMP: Exceptions should be caught by constant reference", commit 0cf2baf by Hans (@hjmjohnson), merged on 14 December 2019. |
Replaced `catch \((\S+) &` & with `catch \(const $1 &`, using Notepad++ v8.3.3, Find in Files, Search Mode: Regular expression. Follow-up to ITK pull request InsightSoftwareConsortium/ITK#3419 commit InsightSoftwareConsortium/ITK@f222a5e (merged on May 11, 2022)
Replaced
catch \((\w+) &
withcatch (const $1 &
, using Visual Studio 2019, Find and Replace, Replace in Files, Use regular expressions.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-referenceDiscussed at C++ Core Guidelines issue isocpp/CppCoreGuidelines#518 "Catch exceptions by const reference?", from February 3, 2016.