Bug #3221
closedcode-style: rule 1.11 contains suboptimal examples
100%
Description
In the examples of code style rule 1.11 the exception is caught by non-const reference.
Some developer is using this example as an excuse for not adding the const
specifier where appropriate.
The examples should be changed to use const Exception&
.
The exception object is never modified inside the catch
block, therefore the normal rule that we use everywhere else of marking methods, parameters, and variables const
when they are not/cannot be modified should be applied here too.
It is true that exceptions are generally immutable, but using const
doesn't cost anything and gives more consistency to the codebase.
Moreover, since we started using Boost.Exception, we can add more details to the exception as it propagates up the call stack, so properly using const
now becomes even more important and allows to understand immediately if the catch
block modifies the exception or not.
Updated by Davide Pesavento about 9 years ago
- Status changed from New to Code review
- % Done changed from 0 to 100
Updated by Junxiao Shi about 9 years ago
- Subject changed from Rule 1.11 contains suboptimal examples to code-style: rule 1.11 contains suboptimal examples
- Description updated (diff)
Agreed.
Updated by Davide Pesavento about 9 years ago
- Status changed from Code review to Closed