when will we have `@nogc nothrow` value exceptions in D?
Paul Backus
snarwin at gmail.com
Sat Jun 4 00:39:28 UTC 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
More information about the Digitalmars-d
mailing list