Alternatives to exceptions for error handling
Paul Backus
snarwin at gmail.com
Sun Nov 22 18:21:44 UTC 2020
On Sunday, 22 November 2020 at 17:37:18 UTC, Roman Kashitsyn
wrote:
> So my question is: does/will D provide support for alternative
> approaches to error handling? In practice, this typically
> includes 2 things:
>
> 1. A sum type that contains either a result or an error. Like
> Result in Rust or Expected that Andrei proposed for C++. It's
> easy to implement in D, but having this in Phobos would be nice.
The biggest blocker for this is that D currently has no
equivalent of Rust's `#[must_use]` and C++'s `[[nodiscard]]`. I
have a DIP in the works to address this:
https://github.com/dlang/DIPs/pull/193
> 2. Some kind of syntactic sugar for propagating errors upstream
> (? macro in Rust, check/handle proposal in Go
> https://go.googlesource.com/proposal/+/master/design/go2draft-error-handling.md, an ugly macro in C++, etc.).
So far the only proposal I've heard on this front is the idea of
bringing Herb Sutter's deterministic exceptions [1] to D. But
there are no concrete plans at this point, not even a DIP.
My expectation is that, like in Rust, the first thing to arrive
will be monadic `map`/`flatMap` methods, since those can be
implemented using only library code.
[1]
http://open-std.org/JTC1/SC22/WG21/docs/papers/2018/p0709r0.pdf
More information about the Digitalmars-d
mailing list