[Issue 17760] New: catch block fails to catch Exception subclass when another Exception is in transit
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Thu Aug 17 15:18:26 PDT 2017
https://issues.dlang.org/show_bug.cgi?id=17760
Issue ID: 17760
Summary: catch block fails to catch Exception subclass when
another Exception is in transit
Product: D
Version: D2
Hardware: x86_64
OS: Linux
Status: NEW
Severity: normal
Priority: P1
Component: druntime
Assignee: nobody at puremagic.com
Reporter: hsteoh at quickfur.ath.cx
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.
--
More information about the Digitalmars-d-bugs
mailing list