anonymous functions and scope(exit)
jfondren
julian.fondren at gmail.com
Sun Jul 4 10:35:45 UTC 2021
On Sunday, 4 July 2021 at 10:07:08 UTC, jfondren wrote:
> By that, what you're running into is an unpleasant interaction
> between
> 1. scope(exit)s that you're writing
> 2. Errors being thrown rather than Exceptions
> 3. anonymous functions getting inferred as nothrow
> And a resolution could be to submit an issue to make #1 prevent
> #3: if someone wants nothrow on an anonoymous function with
> scope guards, they have to make it explicit.
>
Although taking the example code and giving the anonymous
function a name does not actually change this behavior. It really
has to potentially throw a non-Error exception, like
```d
if (ptr is null) throw new Exception("null");
```
There are options like "add a debugging flag to not treat Errors
differently"... but you know, you're going to have gaps in what
you can reasonably test anyway, like code that calls libc exit(),
or code that SIGKILLs itself, or code that enters an infinite
loop. You could document some issues with catching non-catchable
exceptions.
More information about the Digitalmars-d-learn
mailing list