The more I use sum types for error handling the more convinced I am that exceptions are very good, actually.
Conversation
I really loved rusts approach to errors but I haven't actually written anything with it, what's been aggravating in practice?
1
Honestly, everything. I don't find there's much to recommend the practice. You end up being forced to write a lot of boilerplate to handle errors that you just want to propagate (or you just call panic), and you lose a lot of the generic context of exceptions.
4
3
(The main benefit is assurance of having exhaustively handled the possible error cases.)
1
1
I really like OCaml's ad hoc sum types where you only specify what you want, at the site of usage.
1
2
Right, you usually *can't* handle *all* the branches in an error sum. But you can usually handle one or two. You lose the guarantee that you handled those branches, unless you come up with a whole new ADT to represent it.
1
1
Yeah, brought this up here: twitter.com/brendanzab/sta - as stated there it could also save on the boilerplate in making a new error type whenever you want to combine existing errors.
Quote Tweet
Replying to @brendanzab @DRMacIver and @CartesianDaemon
Hypothetically, would extensible variants (like in OCaml) solve some of the boilerplate woes? I often find most of the bolierplate is in defining error types and the required `From` impls (I think there's a derive crate for those though).
i wonder if #DerivingVia could help here // cc
the issue is you have two different sum types and want to combine them into one without much boilerplate
data A = A1 | A2
data B = B1 | B2
2
Generic-lens makes this really nice as you can use Either to pluck types out
1





