More exception classes into Phobos?

Jonathan M Davis via Digitalmars-d digitalmars-d at puremagic.com
Thu Mar 23 02:48:54 PDT 2017


On Thursday, March 23, 2017 09:31:23 Георгий via Digitalmars-d wrote:
> Well, I just suggest to add these 3 classes in std.exception.
>
> NotImplementedException : Exception
> UserInputException : Exception
> IOException : Exception
>
> What do you think?

IMHO, an exception about something not being implemented is indicative of a
bad design. If a class implements an interface, it should implement all of
the functions of that interface, or there's a bug in the design. Similarly,
if a function exists but has no implementation yet, it should use assert(0).
Promoting any kind of exception for "not implemented" as being standard
seems like a completely terrible idea to me.

As for the others, I think that they're so generic that you might as well
just use Exception. It makes a lot more sense to me to use specific
exceptions for specific use cases, not general use cases. For the type to
matter, it has to be something that you're going to operate on differently
than you would other exception types, and that implies that they're tied to
fairly specific error conditions and not anything general. So, I don't think
that we should be adding more exception types to Phobos without a really
good reason for it, and if we do, it's likely for something that's specific
to a particular portion of Phobos rather than for general use. I think that
adding new exceptions to std.exception is exactly the wrong thing to be
doing.

- Jonathan M Davis




More information about the Digitalmars-d mailing list