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 #1

Updated by Davide Pesavento about 9 years ago

  • Status changed from New to Code review
  • % Done changed from 0 to 100
Actions #2

Updated by Alex Afanasyev about 9 years ago

+1

Actions #3

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.

Actions #4

Updated by Davide Pesavento about 9 years ago

Thanks.

Actions #5

Updated by Davide Pesavento about 9 years ago

  • Status changed from Code review to Closed
Actions

Also available in: Atom PDF