Bug 16177 – Inner exception cannot be caught by specific type; becomes a collateral of the original exception

Status
RESOLVED
Resolution
WORKSFORME
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2016-06-16T22:27:03Z
Last change time
2022-11-09T16:35:25Z
Assigned to
No Owner
Creator
Ali Cehreli

Comments

Comment #0 by acehreli — 2016-06-16T22:27:03Z
(This may be related to bug 15467.) The inner exception cannot be caught by its own specific type. Because of that, it becomes a collateral of the original exception. /* This BUG manifests itself on two conditions: 1) scope statement in main() must be 'exit' (change it to 'failure' and there is no bug.) 2) bar() must catch by specific exception type Bar (alias TypeToCatch to Exception or Throwable in bar() and there is no bug.) */ class Foo : Exception { this() { super("Foo"); } } class Bar : Exception { this() { super("Bar"); } } void main() { /* First, a sanity check that bar() does indeed handle its * own exception. */ bar(); try { /* bar() will throw and handle it's own exception while a * Foo is in flight. */ scope (exit) bar(); /* This exception will be in flight while bar() throws * and handles its own exception. */ throw new Foo(); } catch (Foo e) { /* Since bar() has supposedly handled its own exception, * we expect no collateral exception here. */ assert(e.next is null); // THIS ASSERT FAILS } } void bar() { bool caught = false; alias TypeToCatch = Bar; try { throw new Bar(); } catch (TypeToCatch e) { caught = true; } assert(caught); } Ali
Comment #1 by razvan.nitu1305 — 2022-11-09T15:02:33Z
Hi Ali! I cannot reproduce this bug report so maybe the bug has been fixed? I will close this as WORKSFORME. But please reopen if you can reproduce. Cheers, RazvanN
Comment #2 by acehreli — 2022-11-09T16:35:25Z
Thank you!