digitalmars.D - when will we have ` nogc nothrow` value exceptions in D?
- Moth (5/5) Jun 03 2022 right now, trying to emulate exceptions in `@nogc nothrow` code
- Paul Backus (14/19) Jun 03 2022 Realistically: there's a good chance D never gets language
right now, trying to emulate exceptions in ` nogc nothrow` code
means i have to add 50 `if (errorCode != ErrorCode.Ok) { return
errorCode }`s everywhere, and use out parameters if i want to
actually return anything. it would be so much nicer [and
cleaner!] if there was some kind of language support for this.
Jun 03 2022
On Friday, 3 June 2022 at 23:13:39 UTC, Moth wrote:
right now, trying to emulate exceptions in ` nogc nothrow` code
means i have to add 50 `if (errorCode != ErrorCode.Ok) { return
errorCode }`s everywhere, and use out parameters if i want to
actually return anything. it would be so much nicer [and
cleaner!] if there was some kind of language support for this.
Realistically: there's a good chance D never gets language
support for this, and even if it does, it'll probably be a long
time.
The best we can do in the short term is a Rust-style `Result`
type with methods like [`andThen`][1], [`map`][2], and
[`mapErr`][3] that allow us to chain functions together in a
pipeline that automatically propagates errors.
[1]:
https://doc.rust-lang.org/std/result/enum.Result.html#method.and_then
[2]:
https://doc.rust-lang.org/std/result/enum.Result.html#method.map
[3]:
https://doc.rust-lang.org/std/result/enum.Result.html#method.map_err
Jun 03 2022








Paul Backus <snarwin gmail.com>