AFAIK, it wouldn’t be type-safe to have polymorphic exceptions. Consider this hypothetical code:
exception ServerError('a)
let f = x =>
switch x {
| true => raise(ServerError(1))
| false => raise(ServerError("foo"))
}
try {
f(bar)
} catch {
| ServerError(x) => x // what type is x?
}
You either need to have a different exception for each type of payload, or use a monomorphic variant inside it.
exception ServerErrorInt(int)
exception ServerErrorString(string)
// or
type stringOrInt = String(string) | Int(int)
exception ServerError(stringOrInt)