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.