Re: Exception specification checked at *runtime*?
On 2007-11-01 20:38, Paul Brettschneider wrote:
Hello everyone,
I wanted to start adding exception specifications (via throw(...)) to a
project of mine, since it looked like a good idea for the sake of
documentation, giving optimisation-hints to the compiler and getting better
compiler warnings.
It is my understanding that the use of exception specifications is
generally discouraged for a number of reasons, one of them being that it
does not give you any performance boost, on the contrary it can slow
your code down.
In the words of Herb Sutter:
<quote>
In brief, don't bother. Even experts don't bother.
Slightly less briefly, the major issues are:
Exception specifications can cause surprising performance hits, for
example if the compiler turns off inlining for functions with exception
specifications.
A runtime unexpected() error is not always what you want to have happen
for the kinds of mistakes that exception specifications are meant to catch.
You generally can't write useful exception specifications for function
templates anyway because you generally can't tell what the types they
operate on might throw.
</quote>
You can also read the Boost exception specification rationale on their
site: http://www.boost.org/more/lib_guide.htm#Exception-specification
I think the one exception to the rule is to use the empty exception
specification to indicate that no exceptions will ever be thrown.
For documentation a comment with the function will work just as well.
--
Erik Wikstr??m