June 03, 2022

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.

June 04, 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, map, and mapErr that allow us to chain functions together in a pipeline that automatically propagates errors.