Try blocks are trying

FeepingCreature feepingcreature at gmail.com
Tue Oct 12 07:23:41 UTC 2021


On Monday, 11 October 2021 at 16:23:30 UTC, Paul Backus wrote:
> On Monday, 11 October 2021 at 16:04:00 UTC, FeepingCreature 
> wrote:
>> Sure, but then you can't get at the `V` without - going into a 
>> subscope again. :) Though I guess it wouldn't be covered by a 
>> `try`.
>
> At some point, you need to have separate code paths for the 
> error case and the success case, yes. I know of no language 
> construct in D that allows you to create separate code paths 
> without introducing a scope somewhere. The best you can do is 
> move the scopes around.

Right, hence `export try`.

> In D, you can also write `auto x = frgl();`, and it will 
> propagate the exception automatically. :)
>
> This is not a replacement for `try` blocks, because the reason 
> you use a `try` block is to handle an exception locally; in 
> other words, to avoid propagating it.

Right, sorry. I've been meaning to add a feature for that: 
`frgl().handle(Exception ex: return false;)`, but it isn't in yet.


More information about the Digitalmars-d mailing list