logoalt Hacker News

gdotdesign • yesterday at 1:15 PM • 4 replies • view on HN

Roc seems to have a pretty good version of error handling I've seen so far: https://roc-lang.org/docs/main/langref/errors/

Basically you can handle the errors you want to handle and propagate everything else upstream because the error value is a union of all propagated errors. In other (typed) languages you either need to handle all errors or map the different types into a single one.


Replies

stefanka • yesterday at 2:23 PM

Have a look at the eros crate for rust. It implements a convenient error set mechanism mostly without macros

➕ show 1 reply
Groxx • yesterday at 6:18 PM

    y = U64.from_str(b) ? InvalidSecond   
    # returns Err(InvalidSecond(BadNumStr))
Ooo, I like that syntax. Implicit wrapping, but it gives you a type you control so you can <do stuff> if needed.
rixed • yesterday at 9:02 PM

Isn't that how exceptions work, as the union of all possible defined exceptions?

➕ show 1 reply
guenthert • yesterday at 5:09 PM

No recovery / restarts though.