Bug 22143 – Throwable ctor doesn't increment chained exception's ref count

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
druntime
Product
D
Version
D2
Platform
All
OS
All
Creation time
2021-07-25T19:58:37Z
Last change time
2021-08-01T13:09:59Z
Keywords
pull
Assigned to
No Owner
Creator
Richard Manthorpe

Comments

Comment #0 by rmanth — 2021-07-25T19:58:37Z
If you catch a dip1008 ref-counted throwable and pass it into the constructor of an `Error` or `Exception` the ref count isn't incremented. You have to assign via the `next` property to achieve this. ----------------------------------- module chain void main() { try { throw new Exception("reasons..."); } catch(Exception e1) { auto rc1 = e1.refcount(); auto e2 = new Exception("stuff...", e1); // should increment ref count assert(e1.refcount() == rc1+1); // Assertion failure } } ------------------------------------ dmd -preview=dip1008 -run chain.d [email protected](10): Assertion failure
Comment #1 by dlang-bot — 2021-07-25T21:41:36Z
@rmanthorpe created dlang/druntime pull request #3525 "Fix Issue 22143 - Throwable ctor doesn't increment chained exception's ref count" fixing this issue: - Fix Issue 22143 - Throwable ctor doesn't increment chained exception's ref count https://github.com/dlang/druntime/pull/3525
Comment #2 by dlang-bot — 2021-08-01T13:09:59Z
dlang/druntime pull request #3525 "Fix Issue 22143 - Throwable ctor doesn't increment chained exception's ref count" was merged into master: - ae4b02c4685ea217f2da8dd6b83fc117b29af7d4 by Richard Manthorpe: Fix Issue 22143 - Throwable ctor doesn't increment chained exception's ref count https://github.com/dlang/druntime/pull/3525