More exception classes into Phobos?

Jonathan M Davis via Digitalmars-d digitalmars-d at puremagic.com
Thu Mar 23 18:18:58 PDT 2017


On Thursday, March 23, 2017 22:41:39 Георгий via Digitalmars-d wrote:
> On Thursday, 23 March 2017 at 22:12:23 UTC, Георгий wrote:
> > Is there the catch statements, that are active only for such
> > exceptions, that is match multiple types (implements all
> > enumerated interfaces) - if we want to catch a very specific
> > case.
>
> https://dpaste.dzfl.pl/246264774900
> No, it can't be catched by interface at all.

catch can only catch Throwable or any class derived from Throwable (normally
though, you'd only catch Exception or classes derived from it). As such, you
cannot catch an interface. Now, you _can_ catch a base type and then attempt
to cast it to various interfaces if you want to, but that would be more or
less the same as catching an exception type with an error code and having
the catch block's behavior depend on the error code. These restrictions are
the result of trying to avoid the C++ mess of being able to catch stuff like
string or int.

- Jonathan M Davis




More information about the Digitalmars-d mailing list