We've come to be pretty leery of exceptions at Jane Street, and we've had some experience trying to control their use Some quick observations on the current proposal:
- Banning exceptions outright seems too strict. Our tendency has been to have two versions of the function, e.g., Map.find and Map.find_exn. (Our previous approach would have been to use Map.find_opt for the one that returns and option and Map.find for the exception-throwing one, but we're slowly migrating to the first proposal.) The goal is to make the user aware that an exception is reasonably likely, rather than ban exceptions.
- We've played around with monadic error systems that combine errors into a big polymorphic variant. The key practical problem we hit were obscenely complicated error messages. Still, in some cases, monads are very nice.
- Having a variant type other than option so you can specify various different errors (ours is Ok of 'a | Error of 'b) is a good idea. And I think it's common enough that you should define it in your core library as an ordinary variant and make it available everywhere.
y
_______________________________________________