module Exn:sig..end
sexp_of_t uses a global table of sexp converters. To register a converter for a new
exception, add "with sexp" to its definition. If no suitable converter is found, the
standard converter in Printexc will be used to generate an atomic S-expression.typet =exn
sexp_of_t uses a global table of sexp converters. To register a converter for a new
exception, add "with sexp" to its definition. If no suitable converter is found, the
standard converter in Printexc will be used to generate an atomic S-expression.include Pretty_printer.S
exception Finally of t * t
exception Reraised of string * t
val raise_without_backtrace : t -> 'araise, except that the backtrace is not recorded.val reraise : t -> string -> 'a
val reraisef : t -> ('a, unit, string, unit -> 'b) Pervasives.format4 -> 'aformat4 are hard to read, so here's an example.
let foobar str =
try
...
with exn ->
Exn.reraisef exn "Foobar is buggy on: %s" str ()
val to_string : t -> string
val to_string_mach : t -> string
val protectx : f:('a -> 'b) -> 'a -> finally:('a -> unit) -> 'bf and afterwards executes finally, whether f throws an exception or
not.val protect : f:(unit -> 'a) -> finally:(unit -> unit) -> 'a
val handle_uncaught : exit:bool -> (unit -> unit) -> unithandle_uncaught ~exit f catches an exception escaping f and prints an error
message to stderr. Exits with return code 1 if exit is true. Otherwise returns
unit.val handle_uncaught_and_exit : (unit -> 'a) -> 'ahandle_uncaught_and_exit f returns f (), unless that raises, in which case it
prints the exception and exits nonzero.val reraise_uncaught : string -> (unit -> 'a) -> 'aExample:
let rogue_function () = if Random.bool () then failwith "foo" else 3
let traced_function () = Exn.reraise_uncaught "rogue_function" rogue_function
traced_function ();;
: Program died with Reraised("rogue_function", Failure "foo")val does_raise : (unit -> 'a) -> booldoes_raise f returns true iff f () raises, which is often useful in unit
tests.val backtrace : unit -> stringPrintexc.get_backtraceval sexp_of_t : t -> Sexplib.Sexp.traise, except that the backtrace is not recorded.format4 are hard to read, so here's an example.
let foobar str =
try
...
with exn ->
Exn.reraisef exn "Foobar is buggy on: %s" str ()
f and afterwards executes finally, whether f throws an exception or
not.handle_uncaught ~exit f catches an exception escaping f and prints an error
message to stderr. Exits with return code 1 if exit is true. Otherwise returns
unit.handle_uncaught_and_exit f returns f (), unless that raises, in which case it
prints the exception and exits nonzero.Example:
let rogue_function () = if Random.bool () then failwith "foo" else 3
let traced_function () = Exn.reraise_uncaught "rogue_function" rogue_function
traced_function ();;
: Program died with Reraised("rogue_function", Failure "foo")does_raise f returns true iff f () raises, which is often useful in unit
tests.Printexc.get_backtrace