Bug 17760 – catch block fails to catch Exception subclass when another Exception is in transit

Status
NEW
Severity
normal
Priority
P3
Component
druntime
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2017-08-17T22:18:26Z
Last change time
2024-12-07T13:37:32Z
Assigned to
No Owner
Creator
hsteoh
Moved to GitHub: dmd#17349 →

Comments

Comment #0 by hsteoh — 2017-08-17T22:18:26Z
Code: --------- import std.stdio; class MyException : Exception { this() { super("MYMY"); } } struct S { ~this() { try { throw new MyException; } catch(MyException e) { writefln("Collected MyException: %s", e.msg); } catch(Exception e) { writefln("Collected Exception: %s", e.msg); } } void method() { throw new Exception("Dumb error"); } } void main() { try { S s; s.method(); } catch(Exception) {} } --------- Expected output: --------- Collected MyException: MYMY --------- Actual output: --------- Collected Exception: MYMY --------- This appears to happen only when another Exception is in transit. If S is destructed normally at the end of the block rather than as part of exception winding (e.g., if the call to s.method() is commented out), the catch block works as expected.
Comment #1 by hsteoh — 2017-08-17T22:19:28Z
May be related to bug #16799.
Comment #2 by hsteoh — 2017-08-17T22:19:38Z
Comment #3 by bugzilla — 2017-08-19T00:04:20Z
Comment #4 by robert.schadek — 2024-12-07T13:37:32Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/17349 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB