Can we make Throwable an interface?

H. S. Teoh via Digitalmars-d digitalmars-d at puremagic.com
Wed Dec 10 12:01:10 PST 2014


On Wed, Dec 10, 2014 at 10:47:46PM +0300, Dmitry Olshansky via Digitalmars-d wrote:
> 10-Dec-2014 11:20, Kagamin пишет:
> >On Tuesday, 9 December 2014 at 18:07:16 UTC, H. S. Teoh via
> >Digitalmars-d wrote:
> >>what is more interesting is "was this failure caused by permission
> >>error?".
> >
> >And what if it does?
> >You would create thousands of types and their cartesian products just
> >to check for one of them?
> 
> There is no need for cartesian products.
> E.g.
> interface ConversionException { }
> interface Overflow : ConversionException  {}
> interface Underflow : ConversionException  {}
> ...
> 
> Basically enum in DIP 33 expends to a set of dervied interfaces.
> 
> Anyhow enums do not allow one to catch based on them which already
> makes them highly unusable.
[...]

Exactly, that's what makes interfaces a good solution to this. Enums are
also non-extensible, since once Phobos fixes the enum values, user code
cannot extend it, even if a user-defined Exception naturally falls under
one of the preexisting exception categories. Using interfaces would
allow users to leverage the existing exception hierarchy instead of
reinventing the square wheel every time.


T

-- 
This is not a sentence.


More information about the Digitalmars-d mailing list