Any chance that someone can fix this?
I wouldn't rate this as regression because it's extremely old.
Comment #3 by mathias.lang — 2016-02-10T15:34:07Z
Is this example valid ? The specs says:
A scope(exit) or scope(success) statement may not exit with a throw, goto, break, continue, or return; nor may it be entered with a goto.
http://dlang.org/spec/statement.html#ScopeGuardStatement
Comment #4 by dlang-bugzilla — 2016-02-10T15:37:49Z
If that's true, then the code inside them must be enforced as @nothrow, but I bet that would break a ton of D code.
It might be that the spec is outdated. Adding spec keyboard.
Comment #5 by bugzilla — 2020-11-08T06:10:51Z
Throwing inside the scope statement is what's called a "double fault exception". In C++, doing such aborts the program. Andrei proposed extending D to handle this with "exception chaining" and Don Clugston implemented it.
Unfortunately, exception chaining turns out to be very confusing in its semantics. Worse, it doesn't fit in well with the exception unwinding schemes we'd like D to fit in with.
The spec is correct here, and the compiler should deprecate throwing in the scope statement.
Comment #6 by dlang-bugzilla — 2020-11-08T06:25:02Z
I can understand such limitations being present for scope(exit), but not for scope(success). scope(success) blocks are trivially lowered by inserting code before all returns (or other statements that normally leave the scope), so they should not in principle be special as far as exceptions are concerned.
If the problem is generally about throwing while an exception is in flight, I feel like this is too useful to give up at the point, because error recovery in principle may be a non-trivial operation that itself may throw.
> The spec is correct here, and the compiler should deprecate throwing in the
> scope statement.
Such a deprecation would need to be about any and all nothrow code, not just throw statements, which would be a major breaking change. It would, at least, break the pattern:
foreach (foo; foos)
{
scope(failure) stderr.writeln("Error while processing foo" , foo, ":");
processFoo(foo);
}
because the writeln may throw.
Comment #7 by dlang-bugzilla — 2020-11-08T06:26:09Z
(In reply to Vladimir Panteleev from comment #6)
> Such a deprecation would need to be about any and all nothrow code,
non-nothrow code*
Comment #8 by razvan.nitu1305 — 2022-12-06T13:26:10Z
I cannot reproduce the crash. I'm getting the failure exception being thrown. That's because the scope(failure) simply rewrites to:
int careful()
{
try
{
scope(success) throw new Exception("Success");
return victim();
}
catch(Exception)
{
throw new Exception("Failure");
}
}
Is this on par with your expectations Vladimir?