Scope failure is not preventing application crush in case of uncaught exceptions

Jonathan M Davis newsgroup.d at jmdavisprog.com
Sun Dec 17 00:44:54 UTC 2017


On Sunday, December 17, 2017 00:10:27 Anonymouse via Digitalmars-d-learn 
wrote:
> On Saturday, 16 December 2017 at 21:56:49 UTC, Jonathan M Davis
>
> wrote:
> > The only way to catch an exception is with a catch block, and
> > if you do
>
> If you return inside a scopeguard though, the exception (or
> error!) is swallowed. https://run.dlang.io/is/GEtQ6D
>
> void main()
> {
>      foo();
>      writeln("no error!");
> }
>
> int foo()
> {
>      scope(failure) return -1;
>      assert(0);
> }

Which is arguably a bug. The problem stems from the fact that scope
statements get lowered to try-catch-finally blocks. But the entire purposed
of scope statements is to be able to do stuff while an exception is in
flight, not to actually handle the exception or affect it in any way.

- Jonathan M Davis



More information about the Digitalmars-d-learn mailing list