More exception classes into Phobos?

Walter Bright via Digitalmars-d digitalmars-d at puremagic.com
Thu Mar 23 12:47:29 PDT 2017


On 3/23/2017 9:44 AM, Jonathan M Davis via Digitalmars-d wrote:
> My point was that having an exception for something that is not implemented
> like Java did is a horrible design mistake and thus should not be promoted
> by D's standard library. Classes should not be implementing interfaces only
> to throw exceptions when they don't really want to be implementing some of
> the functionality of that interface. That's just plain bad design.
>
> If a programmer is looking to temporarily indicate that a function is
> unimplemented, then normally, the correct thing to do is to assert(0). And
> even if a programmer has a use case where it makes sense to temporarily
> throw an exception due to a lack of implementation rather than considering
> it a bug to call an unfinished function, then that's something internal to
> their application and thus not part of any public API and thus would not
> need to be standard.
>
> As for the other proposed exceptions such as IOException, I think that
> they're so generic as to be borderline useless. When you catch an exception,
> it has to be specific enough to what you're calling to actually be able to
> rely on what it means and actually be able to react to it differently based
> on its type, and "something related to I/O somewhere in the chain of
> functions that I just called just failed" isn't really much different from
> "something somewhere in the chain of functions that I just called just
> failed," which is basically the difference between IOException and
> Exception, especially if IOException is used by a bunch of different
> libraries all over the place, whereas if it's specific to a library that
> you're using, at least you can rely on where it came from and thus rely on
> what it means on some level.
>
> I honestly think that trying to standardize exceptions is a bad idea. They
> _should_ be specific to specific libraries or applications, otherwise
> they're not much different from just throwing Exception.

Thanks for expressing this better than I could have. Over time I've found that 
standardized Exception types seem to become less and less useful over just using 
"Exception" with an appropriate message.



More information about the Digitalmars-d mailing list