Bug 15652 – Alias this exceptions cannot be caught, but shadow others

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2016-02-07T20:54:58Z
Last change time
2024-12-13T18:46:48Z
Assigned to
No Owner
Creator
Lars T. Kyllingstad
Moved to GitHub: dmd#19097 →

Comments

Comment #0 by post — 2016-02-07T20:54:58Z
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
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/19097 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB