Attribute transference from callbacks?

Zach Tollen notmyrealemail at whatever.eee
Sun Dec 15 15:01:08 UTC 2024


On Sunday, 15 December 2024 at 09:15:07 UTC, Richard (Rikki) 
Andrew Cattermole wrote:
> In your previous example you had the sink call wrapped in a try 
> catch statement. That'll work.
>
> ```d
> void f(void delegate() del) nothrow {
> 	try {
> 		del();
> 	} catch (Exception) {
> 	}
> }
> ```

What would also work would be, only in the case of `throw`, to 
statically disallow passing a throwing delegate to a `nothrow` 
function. So:
```d
// still allowed under the new system
void g(void delegate() sink) nothrow {
     sink();
}

void h() {
     g(() { throw new Exception(""); } ); // Error: `nothrow` 
function g() called with delegate which has been inferred `throw`
}
```


More information about the Digitalmars-d mailing list