nothrow and std.exception.ifThrown
Meta
jared771 at gmail.com
Fri Apr 30 14:10:25 UTC 2021
On Friday, 30 April 2021 at 13:42:49 UTC, Steven Schveighoffer
wrote:
> On 4/30/21 9:24 AM, Meta wrote:
>
> My point is that I think marking the *function* nothrow is not
> correct, it's the second parameter that dictates the throwing
> of the result.
>
> And you can probably fix the second parameter to be a templated
> delegate:
>
> ```d
> CommonType!(T1, T2) ifThrown(E : Throwable = Exception, T1,
> T2)(lazy scope T1 expression, scope T2 errorHandler) if
> (is(typeof(errorHandler(E.init))))
> ```
>
> And of course, we get into chicken-and-egg problems with this
> because if you pass in a lambda, there's no types for it to
> figure this stuff out. Another option is to overload on the
> delegate, but meh. I'd really like to see a language change
> that says "infer the attributes of this function based on the
> fact that it calls the delegate passed in."
>
> -Steve
Now that you mention it, I don't see why lazy parameters can't
have their attributes inferred. What happened to the DIP to
replace lazy parameters with automatic conversion of passed
values to delegates, anyway? I.e.:
```
CommonType!(T1, T2) ifThrown(E: Throwable = Exception, T1,
T2)(scope T1 delegate() expression, scope T2 delegate()
errorHandler);
//getString() and "some string" automatically converted to
`string delegate()`
auto s = getString().ifThrown("some string");
```
More information about the Digitalmars-d-learn
mailing list