DIP33: A standard exception hierarchy
Lars T. Kyllingstad
public at kyllingen.net
Tue Apr 2 13:11:30 PDT 2013
On Tuesday, 2 April 2013 at 10:37:08 UTC, deadalnix wrote:
> On Monday, 1 April 2013 at 11:08:16 UTC, Lars T. Kyllingstad
> wrote:
>> It's time to clean up this mess.
>>
>> http://wiki.dlang.org/DIP33
>
> Several things.
>
> First the usage of enums isn't the right path. This makes it
> hard to extend in general, and it is a poor man replacement for
> sub classes in general.
Phobos/druntime devs can always add to the enums. Users still
have the option of subclassing if strictly necessary.
> As a rule of thumb, when you use switch in OOP code, you are
> likely to do something wrong.
I'm not sure I agree with that rule. And anyway, D's final
switch mitigate some of the problems with classic switch.
> Second, many of you error are recoverable here. It isn't quite
> satisfying.
>
> RangeError is a very bad thing IMO. It completely hides why the
> range fails in the first place. Trying to access front when not
> possible for instance, is an error for a reason (which is range
> dependent). That reason must be the source of the
> error/exception.
No. To call front on an empty range is a programming error,
plain and simple. It's like trying to access the first element
of an empty array. The fact that some ranges may allow it anyway
does not change anything.
> In general the hierarchy is weird. Why isn't
> NetworkingException (why not NetworkException ?) a subclass of
> IOException ?
Because they are supposed to signal different error conditions.
> OutOfMemoryError on its own isn't good IMO. The Error hierarchy
> is made for error that aren't recoverable (or may not be
> recoverable). It include a whole class of problem, and OOM is
> only one of them (another example is Stack overflow errors).
The DIP sort of redefines Error to mean "programming error".
Lars
More information about the Digitalmars-d
mailing list