Project

General

Profile

Bug #3221

Updated by Junxiao Shi over 8 years ago

In the examples of code style rule 1.11 the exception is caught by non-const reference. 
 Some developer Junxiao 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.

Back