|RE: [cdt-dev] Codan warning "Catch uses reference to exception"|
Ouch, my intention when proposing this checker (https://bugs.eclipse.org/bugs/show_bug.cgi?id=281187) was exactly to make sure that no-one declares the exception parameter other than by reference, as Doug and Andrew already pointed out. This is really frequent mistake I see in code reviews I conduct. Looks like an unfortunate misunderstanding.
Shall I enter a new CR?
cdt-dev-bounces@xxxxxxxxxxx [mailto:cdt-dev-bounces@xxxxxxxxxxx] On Behalf Of Doug Schaefer
When I did use exceptions in a previous life, I did catch by reference. I'm not sure how exceptions get implemented, but it seemed catching by value was a bad idea since it would theoretically mean always calling the copy constructor on the catch, which could lead to more problems.
On Thu, Mar 25, 2010 at 9:10 PM, Andrew Gvozdev <angvoz.dev@xxxxxxxxx> wrote:
Why do you want us to avoid catching exceptions by reference? Shouldn't it be the other way around? Catching by reference is recommended by C++ experts, for example Herb Sutter/Andrei Alexandresscu "C++ Coding Standards", Rule 73 "Throw by value, catch by reference". For one thing, this avoids copying and potentially slicing the exception.
Back to the top