Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [cdt-dev] Codan warning "Catch uses reference to exception"

I am not good at C++. I misunderstood the request. Just re-open it I reverse the checker :)

Elmenthaler, Jens wrote:

Ouch, my intention when proposing this checker ( 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?




From: cdt-dev-bounces@xxxxxxxxxxx [mailto:cdt-dev-bounces@xxxxxxxxxxx] On Behalf Of Doug Schaefer
Sent: Freitag, 26. März 2010 06:55
To: CDT General developers list.
Subject: Re: [cdt-dev] Codan warning "Catch uses reference to exception"


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 <> 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.



cdt-dev mailing list


_______________________________________________ cdt-dev mailing list cdt-dev@xxxxxxxxxxx

Back to the top