Eio.Exn
Eio exceptions.
Describes 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.
A 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.
add_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 ->
'a
reraise_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" addr
You 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 -> err -> bool) -> unit
register_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
.
pp
is a formatter for exceptions.
This is similar to Fmt
.exn, but can do a better job on Io
exceptions because it can format them directly without having to convert to a string first.
module Backend : sig ... end
Extensible backend-specific exceptions.
exception Multiple of with_bt list
Raised 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.
combine 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:
Cancel.Cancelled
exception does nothing, as these don't need to be reported. The result is only Cancelled
if there is no other exception available.Io
errors, then the result is Io (Multiple_io _)
.