Try blocks are trying
Paul Backus
snarwin at gmail.com
Mon Oct 11 13:45:02 UTC 2021
On Monday, 11 October 2021 at 09:27:30 UTC, FeepingCreature wrote:
> One possible solution would be a way to try/catch as an
> expression:
>
> ```
> auto x = frgl().tryCatch(Exception exc: return exc;);
> ```
>
> But D has no precedent for statements embedded in expressions
> like this, so it'd be a major language shift.
```
import std.sumtype;
SumType!(V, E) tryCatch(E, V)(lazy V expr)
{
try return typeof(return)(expr);
catch (E e) return typeof(return)(e);
}
auto x = frgl().tryCatch!Exception;
```
More information about the Digitalmars-d
mailing list