package sugar

  1. Overview
  2. Docs

This signature describes an Error module that has some control over unexpected exceptions.

If you want to handle unexpected exceptions as they appear, you should probably define an error case with the type exn, like in the code below:

module Error = struct
  type t =
    | Because_reasons
    | Unexpected of exn

  let panic e = Unexpected e
end
include Error
type t

This type describes the errors of your project. It's one of the main requirements to create a result monad.

If you don't want to specify your errors upfront, you can still use something like unit or string as error type.

val panic : exn -> t

When an exception is detected, this module can either terminate the process with a proper message or chose convert the error to the type t.