Alternatives to exceptions for error handling
snarwin at gmail.com
Mon Nov 23 11:45:47 UTC 2020
On Monday, 23 November 2020 at 02:14:33 UTC, Vladimir Panteleev
> Another approach that I'm not sure we've explored fully is to
> outright deprecate silently discarding all function return
> values. Functions which return a value that is only sometimes
> useful seem like a relatively rare oddity.
The main advantage of @nodiscard compared to this approach is
that it can interact with the type system. For example, if I
declare a struct like the following:
@nodiscard Result(T, E)
SumType!(T, E) payload;
...then every expression that evaluates to a Result (not just
function calls!) automatically becomes non-discardable.
More information about the Digitalmars-d