Say we have two exception classes, Foo and Bar, where Bar is a subtype of Foo via "alias this":
class Foo : Exception
{
this() { super("Foo"); }
}
class Bar : Exception
{
this()
{
super("Bar");
foo = new Foo;
}
Foo foo;
alias foo this;
}
Now, we try to throw a Bar and catch it as a Foo:
try { throw new Bar; }
catch (Foo) { }
This compiles and runs, but does not work as expected; the exception is not caught. But then, that ought to mean that the following code is perfectly fine:
try { throw new Bar; }
catch (Foo) { /* ... */ } // A
catch (Bar) { /* ... */ } // B
However, this doesn't even compile.
Error: catch at [line A] hides catch at [line B]
I don't know what is supposed to be the correct behaviour here, but one of these cases should work.
Comment #1 by robert.schadek — 2024-12-13T18:46:48Z