[OT] Is there a real alternative to exceptions ?

Basile B. b2.temp at gmx.com
Wed May 27 11:23:02 UTC 2026


On Thursday, 16 January 2025 at 19:02:05 UTC, Basile B. wrote:
> I have the feeling that things like
>
> ```
> a.map!(mapperFun).reduce!(reducerFun).array;
> ```
>
> is only possible thanks to an exception system. A similar 
> expressivity looks impossible for example with the idom of 
> result tuple `(error_code, actuallResult)`.
>
> that problem is currently something rather serious, in the 
> sense that, let's say you want to make a standard library, you 
> really need to have a well defined way of handling errors.
>
> I'll be interested to read your thoughts on that topic.

I have actually, one year later, implemented one of the system 
that was suggested. Not perfect tho. The idea is to feed argument 
with a "result". You have the data but also an indication if 
everthing went nice or not. See this [commit]. You can just write

```
assert( valid().jsonize().writeOutput().toMainResult() == 0);
```

Very few compiler support, I just check that the thing [is used].


[commit]: 
https://gitlab.com/styx-lang/styx/-/commit/14ba3efa21bf46076dd2e98898cced914894ae4c
[is used]: 
https://gitlab.com/styx-lang/styx/-/blob/master/src/styx/semantic/bodies.sx#L280


More information about the Digitalmars-d mailing list