Re: unhandled exceptions and exception specs
On Mar 12, 6:33 am, Jerry Coffin <jcof...@taeus.com> wrote:
In article <1205257098.852...@irys.nyx.net>, ytrem...@nyx.nyx.net
says...
[ ... ]
Exceptions specification are generally considered as almost
useless in C++ because they do not stop these exception
being thrown, simply cause undefinite behaviour:
Actually, the behavior is well defined -- it's just behavior
that almost nobody ever really wants.
What? It's basically the same behavior as an assertion failure.
The exception specification is part of the function's contract,
and if it is violated, you want an assertion failure.
The problem is somewhat more general: with regards to the
contract, there are two things which are generally important to
the client code:
-- it's impossible to write exception safe code without the
guarantee that certain functions (destructors, for example,
or swap if you're using the swap idiom for assignment) will
not generate an exception, so the contract expressed in an
empty exception specifier is very important, and
-- it's important to know that the specific condition X results
in the exception Y being thrown---something, of course, in
which exception specifiers are of no help.
In the end, I think the bad press concerning exception
specifiers is largely based on a misperception of what they
guarantee. What they guarantee is strictly negative: they
guarantee that certain things won't happen. And in practice,
the client is interested either in ) what will happen, when, or
simply in knowing that nothing will happen, that it doesn't have
to worry about recovering from an exception when he calls this
function. (There may be special cases where the client is
interested in only having one specific type of exception, and
nothing else, but they are exceedingly rare.)
--
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