Project

General

Profile

Actions

Bug #3221

closed

code-style: rule 1.11 contains suboptimal examples

Added by Davide Pesavento about 9 years ago. Updated about 9 years ago.

Status:
Closed
Priority:
Normal
Category:
Docs
Target version:
Start date:
Due date:
% Done:

100%

Estimated time:

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.

Actions

Also available in: Atom PDF