[OT] - C++ exceptions are becoming more and more problematic
__StarCanopy
starcanopy at protonmail.com
Sun Feb 27 04:57:28 UTC 2022
On Saturday, 26 February 2022 at 23:56:31 UTC, H. S. Teoh wrote:
> In theory, your own error return type would be a sum type of
> all error returns of the functions you call plus your own error
> codes. In practice, I honestly doubt if anyone would bother
> doing this
I tried to help alleviate this pain by creating a template that
pipes a given sequence of functions, consolidating all possible
types into a new result type.
```d
// Very contrived example
// int, Outcome!(int, IsNegativeError), Outcome!(int,
IsOddError)
chain!(() => -1, isPositive, isEven)()
.handle!(
num => text(num, " is an even, positive integer"),
(IsNegativeError err) => text(err.num, " is a negative
integer"),
(IsOddError err) => text(err.num, " is an odd integer")
) // Outcome!(int, IsNegativeError, IsOddError)
.writeln; // -1 is a negative integer
```
More information about the Digitalmars-d
mailing list