Question about exception specification
Robert Fraser
fraserofthenight at gmail.com
Tue Oct 23 23:05:30 PDT 2007
Graham St Jack Wrote:
> I read WalterAndrei.pdf recently, and liked most of what was in there.
>
> However, there was the line: "Exception specifications: bad idea" on a
> slide that discussed a possible nothrow keyword.
>
> Can anyone explain why they are a bad idea? And if they are in fact a
> bad idea, how do I find out what exceptions can be thrown by a function?
> Eyeballing heaps of code doesn't count as a way!
It's been debated ad infinitum, and there are definite advantages to exception specification, especially in smaller projects. For a large project, though, the general consensus I think is that it reduces productivity considerably while not giving much significant advantage, and it encourages bad programming practices such as:
try
{
// Do stuff
}
catch(Exception e)
{
// ignore
}
... just to avoid exception specification, since the place you actually deal with an exception, in a very large project, could be 9 calls up th hierarchy. It also makes functors, function pointers, closures, delegates, etc. hard to implement.
As for how to determine which exceptions a function throws, that information belongs in the documentation of the function.
FWIW, I agree that for smaller projects/functions, exception specification works quite well.
As for how to determine what
More information about the Digitalmars-d
mailing list