ocaml-core / base / core / lib / or_error.mli

(** Type for tracking errors in an Error.t. This is a specialization of the Result type,
    where the Error constructor carries an Error.t.

    A common idiom is to wrap a function that is not implemented on all platforms, e.g.:

    val do_something_linux_specific : (unit -> unit) Or_error.t

open Sexplib

type 'a t = ('a, Error.t) Result.t

include Sexpable.S1 with type 'a t := 'a t
include Binable .S1 with type 'a t := 'a t
include Monad.S with type 'a t := 'a t

(** Catches any exceptions and returns them in the Result.t as an Error.t *)
val try_with      : (unit -> 'a  ) -> 'a t

(** [try_with_bind f] is like [try_with f], except that [f] can throw exceptions or
    return an Error directly, without ending up with a nested error.  Equivalent to
    [Result.join (try_with f)]. *)
val try_with_bind : (unit -> 'a t) -> 'a t

(** [ok_exn t] throws an exception if [t] is an [Error], and otherwise returns the
    contents of the [Ok] constructor. *)
val ok_exn : 'a t -> 'a

(** [of_exn exn] is [Error (Error.of_exn exn)]. *)
val of_exn : exn -> 'a t

(** [error message value sexp_of_value] constructs an [Error.t] and returns it as a
    [Result.Error]. [error_string] is a sepcial case with ['a = unit]. *)
val error        : string -> 'a -> ('a -> Sexp.t) -> _ t
val error_string : string                         -> _ t

(** [unimplemented name] returns a standard error value for an unimplemented value. *)
val unimplemented : string -> _ t
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.