Module Eio.ExnSource
Eio exceptions.
type with_bt = exn * Stdlib.Printexc.raw_backtraceDescribes the particular error that occurred.
They are typically nested (e.g. Fs (Permission_denied (Unix_error ...))) so that you can match e.g. all IO errors, all file-system errors, all permission denied errors, etc.
If you extend this, use register_pp to add a printer for the new error.
Extra information attached to an IO error. This provides contextual information about what caused the error.
exception Io of Eio.Exn.err * Eio.Exn.contextA general purpose IO exception.
This is used for most errors interacting with the outside world, and is similar to Unix.Unix_error, but more general. An unknown Io error should typically be reported to the user, but does not generally indicate a bug in the program.
type Eio.Exn.err += | Multiple_io of (Eio.Exn.err * Eio.Exn.context * Stdlib.Printexc.raw_backtrace) list(*Error code used when multiple IO errors occur.
This is useful if you want to catch and report all IO errors.
*)
val create : Eio.Exn.err -> exncreate err is an Io exception with an empty context.
val add_context :
exn ->
('a, Stdlib.Format.formatter, unit, exn) Stdlib.format4 ->
'aadd_context ex msg returns a new exception with msg added to ex's context, if ex is an Io exception.
If ex is not an Io exception, this function just returns the original exception.
val reraise_with_context :
exn ->
Stdlib.Printexc.raw_backtrace ->
('a, Stdlib.Format.formatter, unit, 'b) Stdlib.format4 ->
'areraise_with_context ex bt msg raises ex extended with additional information msg.
ex should be an Io exception (if not, is re-raised unmodified).
Example:
try connect addr
with Eio.Io _ as ex ->
let bt = Printexc.get_raw_backtrace () in
reraise_with_context ex bt "connecting to %S" addrYou must get the backtrace before calling any other function in the exception handler to prevent corruption of the backtrace.
val register_pp : (Stdlib.Format.formatter -> Eio.Exn.err -> bool) -> unitregister_pp pp adds pp as a pretty-printer of errors.
pp f err should format err using f, if possible. It should return true on success, or false if it didn't recognise err.
val pp : exn Fmt.tval pp_err : Eio.Exn.err Fmt.tpp_err formats an error code.
val empty_backtrace : Stdlib.Printexc.raw_backtraceA backtrace with no frames.
module Backend : sig ... endExtensible backend-specific exceptions.
type Eio.Exn.err += | X of Eio.Exn.Backend.t(*A top-level code for backend errors that don't yet have a cross-platform classification in Eio.
You should avoid matching on these (in portable code). Instead, request a proper Eio code for them.
*)
exception Multiple of Eio.Exn.with_bt listRaised if multiple fibers fail, to report all the exceptions.
This usually indicates a bug in the program.
Note: If multiple IO errors occur, then you will get Io (Multiple_io _, _) instead of this.
val combine : Eio.Exn.with_bt -> Eio.Exn.with_bt -> Eio.Exn.with_btcombine x y returns a single exception and backtrace to use to represent two errors.
The resulting exception is typically just Multiple [y; x], but various heuristics are used to simplify the result:
- Combining with a
Cancel.Cancelledexception does nothing, as these don't need to be reported. The result is onlyCancelledif there is no other exception available. - If both errors are
Ioerrors, then the result isIo (Multiple_io _).