Can we make Throwable an interface?

Dmitry Olshansky via Digitalmars-d digitalmars-d at puremagic.com
Tue Dec 9 11:05:43 PST 2014


09-Dec-2014 21:05, H. S. Teoh via Digitalmars-d пишет:

>> 1. enums are hard to extend for std lib, and absolutely impossible by
>> 3rd party libraries.
>> 2. Single hierarchy has some appeal but it doesn't allow to catch on
>> similar classes that do not inherit from the same base class.
>> Basically there are many ways to view similarities of excpetions and
>> single hierarchy fails to address that.
>>
>> If we were to replace each class with a base interface and every Kind
>> enum with an interface (inhereting from one or more base interfaces)
>> then we can actually address both of these points.
> [...]
>
> I like this idea!
>
[snip]

> For example, dirEntries may fail due to permission failure, but the user
> is generally not interested in OS-specific error codes like errno or
> Windows error numbers; what is more interesting is "was this failure
> caused by permission error?".
>
> This problem cannot be satisfactorily resolved with a single Exception
> hierarchy, but it *can* be resolved by using interfaces instead of base
> classes. We could then have a WindowsException and a PosixErrnoException
> (for example), and have subclasses also implement a NoAccessException
> interface. Thus you have a class hierarchy based on implementation
> details (e.g., PosixErrorException stores errno, and WindowsException
> stores Windows error codes), but also an interface hierarchy based on
> logical categorizations of exceptions.
>

That's exactly what I aim to do. The question is how hard it's do in 
runtime and if there are any critical assumptions that prevent this.


-- 
Dmitry Olshansky


More information about the Digitalmars-d mailing list