3 ms·
* exceptions for error handling: you can also use the 'result' type (an OK of 'a|Error of 'b type in the stdlib) if you don't like exceptions. At least the func
by edwintorok 5y ago
* exceptions for error handling: you can also use the 'result' type (an OK of 'a|Error of 'b type in the stdlib) if you don't like exceptions.
At least the function's signatures will give more details in how it can fail and force you to handle the failures (or pass them through to your caller).
Unfortunately you lose backtraces that way (though you can use wrappers like reword_error, or logging to give more details on what goes wrong, but backtraces can be convenient in locating the source of an error sometimes).
A compromise is to use a wrapper like trap_exn (from Bos) that puts the exception with its backtrace in the Error type and then you propagate that...