Re: no-throw guarantee for trivial functions?
On Jan 17, 3:11 pm, Maxim Yegorushkin
<maxim.yegorush...@gmail.com> wrote:
On Jan 15, 3:41 pm, James Kanze <james.ka...@gmail.com> wrote:
On Jan 15, 4:28 pm, DerTop...@web.de wrote:
On 14 Jan., 15:29, Maxim Yegorushkin <maxim.yegorush...@gmail.com>
wrote:
[snipped question about exception specifications]
On Jan 14, 1:41 pm, Maik <Beckmann.M...@googlemail.com>
wrote: Read the full
story:http://www.gotw.ca/publications/mill22.htm
Whoa, that sounds devastating.
Yes, but it's very dated, and doesn't correspond to the
general consensus today.
It would be interesting to know what the general consensus
today is.
That no-throw exception specifications are generally advisable,
when applicable.
[]
Exceptions specifications don't incure a performance penalty
with a decent compiler,
Could you post compiler names please?
Could you post one where it does have a performance penalty. I
don't know of one. (It certainly has none with Sun CC, nor
g++.)
and can, in a few cases, even lead to improved optimization
(probably only for empty ones, however).
Could you show those cases please?
Not off hand, but as always, the more information a compiler
has, the better it can optimize. Calling a function without a
no throw exception specification introduces an additional flow
path into the program.
[]
In practice, there are two useful "guarantees" with regards
to exceptions:
-- The function never throws anything. This guarantee is more
or less necessary in a few critical places if you want to
write exception safe code. In C++, it's expressed by using
the "throw()" exception specifier.
Are you talking about overriding std::exception::what() or
something else?
Of course not.
What are those few critical places?
Just about all destructors, for starters. swap() member
functions, if you're using the swap idiom for assignment. More
generally, any time you have to temporarily invalidate the
invariants.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34