Error derived from Exception is WRONG, DAMNIT

Janice Caron caron800 at googlemail.com
Sat Mar 1 23:38:17 PST 2008


On 02/03/2008, Yigal Chripun <yigal100 at gmail.com> wrote:
>  Errors should
>  represent unrecoverable situations

It is important that programs that work in Debug mode should also work
in Release mode. For example: an ArrayBoundsException is not thrown in
Release mode, therefore, it should not be catchable in Debug mode.

However, I don't think that making a distinction between Error and
Exception is the way to go here. I think a better way would be for
ArrayBoundsException to be defined in Phobos as:

    debug class ArrayBoundsException : Exception

That way, if you try to catch one, it will be a /compile-time/ error
when you compile your release build.

Beyond that, I don't think there should be a distinction. Provided
that the axiom "what works in Debug mode also works in Release mode"
holds (assuming the source compiles in both builds), there should be
no need to make this artificial distinction.

For example, if one were to write an operating system in D (a daunting
task, but let's pretend to be ambitious for a moment). I would /not/
want an Error thrown by an application to kill the whole operating
system. At some level, it has to catch the Error and shut down the
errant program. The same may well be true, on a smaller scale, for
applications and plugins - or even just trial routines.



More information about the Digitalmars-d mailing list