Exception vs Result

**ding ding ding ding**

One time was my fault directly (via some of my earliest OCaml code where I used find without thinking much about it), the other was exactly the scenario you describe where a borderline edge case parameter to a library function (I think it was an empty string) ended up touching a map with a non-existent key, alas.

I’m certain I’ve groused in irc about Map.S.find being exception-oriented, while the IMO saner semantics are found under the less-natural/longer find_opt. Defaults matter for things like this, so I greatly prefer the foo_exn naming convention for function variants that raise instead of return.

2 Likes