Denis Perelyubskiy <ne********@dslextreme.com> wrote in message news:<10*************@corp.supernews.com>...
Hello,
In the archives of this newsgroup, I found references
to Jack Reeves' "(B)Leading Edge" column.
<http://www.bleading-edge.com/Publications/list.htm>
At this point, I am particularly interested in the
two columns : "Guidlelines for Throwing Exceptions",
and "Guidelines for Using Exception Specifications".
They're amazingly good given their age. The one on throwing
exceptions is still quite good, though perhaps not strongly enough
worded in places. Just for an obvious example, it tells you not to
throw exceptions from destructors. This is good advice, but IMO it
doesn't really go far enough: in a dtor, you must ensure that not only
do you not throw an exception, but that if you do anything else that
could possibly throw an exception, you must trap it and not allow it
to escape.
Likewise with the article on exception specifications: he advises
against using them if you can avoid it, and gives some advice about
how to limit the damage they do when you use them.
My advice would be simpler: don't use them. Ever. Under any
circumstances or for any reason at all.
Some people advise that an exception (no pun intended) be made for the
empty exception specification, but I disagree even with that. It's
still trouble and it makes your code more fragile -- even when you
write a function that you know can't throw, sometime later it'll
inevitably get modified to do something that can throw under _some_
obscure circumstances, and then you have a latent bug. Worse, it's
probably almost impossible to duplicate under laboratory conditions.
Exception specifications were an idea that seemed like a good idea at
the time, but I think it's fairly safe to say they were a mistake.
It's been argued that exception specifications that are checked at
compile time would be an improvement, but expeience with Java (which
has exactly that) mostly seems to indicate that even these are still a
net loss.
--
Later,
Jerry.
The universe is a figment of its own imagination.