digitalmars.D.bugs - [Issue 15652] New: Alias this exceptions cannot be caught, but
- via Digitalmars-d-bugs (44/44) Feb 07 2016 https://issues.dlang.org/show_bug.cgi?id=15652
https://issues.dlang.org/show_bug.cgi?id=15652 Issue ID: 15652 Summary: Alias this exceptions cannot be caught, but shadow others Product: D Version: D2 Hardware: All OS: All Status: NEW Severity: normal Priority: P1 Component: dmd Assignee: nobody puremagic.com Reporter: bugzilla kyllingen.net 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. --
Feb 07 2016