Comment #0 by Jesse.K.Phillips+D — 2011-11-06T12:54:39Z
When Using Scope Guards to throw additional exceptions chaining is not done. In the example below 'collide' shows normal Exception Chaining. Then 'collideScope' fails all three asserts.
void main()
{
void collide()
{
try
{
try
{
throw new Exception("e");
}
finally
{
throw new Exception("t");
}
}
catch(Exception z)
{
assert(z.msg=="e"); // First thrown Exception
assert(z.next !is null);
assert(z.next.msg=="t"); // Second thrown Exception
}
}
collide();
void collideScope()
{
try
{
scope(failure) throw new Exception("t");
throw new Exception("e");
}
catch(Exception z)
{
assert(z.msg=="e"); // AssertError
assert(z.next !is null); // AssertError
assert(z.next.msg=="t"); // AssertError
}
}
collideScope();
}
Comment #1 by Jesse.K.Phillips+D — 2011-11-06T13:04:08Z
Oh, changing this to a feature request. It works for scope(exit) which matches the finally clause version. I think it would also be good to do chaining with scope(failure) too though. I've made this an enhancement request.
Comment #2 by robert.schadek — 2024-12-13T17:56:44Z