Partial match: Style advice

There is a contradiction here. The precise exception is very important because your context may catch an exception because other functions are using them to report non fatal errors (e.g. Failure). So using, e.g. failwith you may never get that proper backtrace as the context may swallow it.

If you stick to the predefined exceptions, you are basically left with Assert_failure and Invalid_argument which are designed not to be catched by user code.

(Personally I just use assert false, it’s a strong signifier that this should not have happened)