package eio

  1. Overview
  2. Docs
Effect-based direct-style IO API for OCaml

Install

Dune Dependency

Authors

Maintainers

Sources

eio-0.6.tbz
sha256=ead3eea352dd3d7d11a81ffdbeee6ca94d5e6b3f46de264b4e59689360b3ef38
sha512=0543643da7861f533f9b7ebee8aa30a6868b48ae1e19211666a9b860e9ff8d8a9e135f214a4603d0329f2027277701f6ffd900b6fba3405a538eebc301edaf29

doc/src/eio.core/exn.ml.html

Source file exn.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
type with_bt = exn * Printexc.raw_backtrace

exception Multiple of exn list  (* Note: the last exception in list is the first one reported *)

exception Cancelled of exn

exception Cancel_hook_failed of exn list

let () =
  Printexc.register_printer @@ function
  | Multiple exns -> Some ("Multiple exceptions:\n" ^ String.concat "\nand\n" (List.rev_map Printexc.to_string exns))
  | Cancel_hook_failed exns -> Some ("During cancellation:\n" ^ String.concat "\nand\n" (List.map Printexc.to_string exns))
  | Cancelled ex -> Some ("Cancelled: " ^ Printexc.to_string ex)
  | _ -> None

let combine e1 e2 =
  if fst e1 == fst e2 then e1
  else match e1, e2 with
    | (Cancelled _, _), e
    | e, (Cancelled _, _) -> e  (* Don't need to report a cancelled exception if we have something better *)
    | (Multiple exs, _), _ when List.memq (fst e2) exs -> e1   (* Avoid duplicates *)
    | (Multiple exs, bt1), (e2, _) -> Multiple (e2 :: exs), bt1
    | (e1, bt1), (e2, _) -> Multiple [e2; e1], bt1
OCaml

Innovation. Community. Security.