Error derived from Exception is WRONG, DAMNIT

Yigal Chripun yigal100 at gmail.com
Sat Mar 1 16:16:12 PST 2008


Sean Kelly wrote:
> I'm not sure I agree.  First, I think it's important to note that all Errors are Exceptions, so the inheritance
> relationship makes sense.  Also, I feel that all throwable objects should be classified as Exceptions, so I
> don't like the idea of having them both be siblings derived from Throwable.  Finally, while it may be
> easy to catch and ignore Exceptions, I feel very strongly that this is bad programming practice.
> Exceptions should never be caught and ignored--particularly at such a granularity.  I would prefer that
> a library stick to its guns and inspire a change in programmer mindset than to make allowances for such
> mistakes.
>
>
> Sean
>   
The classical OOP example of a square that inherits from a rectangle
comes to mind. sure, you can say that a square is a rectangle but
inheritance in this case will cause breakage. for instance you can
double one of the rectangle's edges. squares that inherit that method
will break because if you double only one edge than you no longer have a
square.
My point is that errors have the same relation to exceptions. There is
additional functionality that  exceptions provide ( you can catch them
and do stuff) which are not part of an error's interface. Errors should
represent unrecoverable situations where the program must terminate.
catching an error is, as downs said, a BUG.

-- Yigal



More information about the Digitalmars-d mailing list