[Exceptional C++ Style] Item 13: A Pragmatic Lookat ExceptionSpecifications

Paul Grenyer paul at paulgrenyer.co.uk
Tue Dec 7 08:55:37 EST 2004


Hi Ric

> > I just assumed it wasn't an error due to MSVC inadequacy. It now appears
> > that MSVC is inline with the standard and "extra" helpful.
>
> Yup. 15.4/10
>
> Note that it's only a warning, not an error.

Yep. :-)

> > I think it would be better if exception specifications were enforced at
> > compile time. What do people think?
>
> This is an old chestnut that comes up on the newsgroups regularly.

That doesn't suprise me. I don't do Newsgroups, they're bad for your health.
:-)

> The quick counter argument is that templates can make things tricky.
>
> Also, there's experience that using exception specs is in general a bad
idea - it exposes implementation detail
> in the signature.

Isn't that the same with const? Or even with a return value to a certain
extent?


> > What about swap functions? For example Herbs copy-swap idiom for class
> > copy-constructors and assignment operators? Should the swap function
there
> > be marked with throw()?
>
> The no-throw spec is one that *may* be worth having as it can enable some
optimisations. But in practice it's
> fraught with danger
>
> And Item #13 does actually have this as a second moral after "Don't use"

Ah yes, so I see.

> > Even as just as documentation to the user for
> > reassurance?
>
> Documentation can do that too, without the potential for unexpected
behaviour.

Yes, but who reads that? ;-)

Regards
Paul

Paul Grenyer
email: paul at paulgrenyer.co.uk
web: http://www.paulgrenyer.co.uk
articles: http://www.paulgrenyer.dyndns.org/articles/

I put my hand upon the lever, said let it rock and let it roll.




More information about the Effective-cpp mailing list