Debian Codegraph @

clib/exninfo.mli

raw symbols SCIP
1 (************************************************************************)
2 (* * The Rocq Prover / The Rocq Development Team *)
3 (* v * Copyright INRIA, CNRS and contributors *)
4 (* <O___,, * (see version control and CREDITS file for authors & dates) *)
5 (* \VV/ **************************************************************)
6 (* // * This file is distributed under the terms of the *)
7 (* * GNU Lesser General Public License Version 2.1 *)
8 (* * (see LICENSE file for the text of the license) *)
9 (************************************************************************)
10
11 (** Additional information worn by exceptions. *)
12
13 type 'a t
14 (** Information containing a given type. *)
15
16 type info
17 (** All information *)
18
19 type iexn = exn * info
20 (** Information-wearing exceptions *)
21
22 val make : string -> 'a t
23 (** Create a new piece of information. *)
24
25 val null : info
26 (** No information *)
27
28 val add : info -> 'a t -> 'a -> info
29 (** Add information to an exception. *)
30
31 val get : info -> 'a t -> 'a option
32 (** Get information worn by an exception. Returns [None] if undefined. *)
33
34 val info : exn -> info
35 (** Retrieve the information of the last exception raised. *)
36
37 type backtrace
38
39 val get_backtrace : info -> backtrace option
40 (** [get_backtrace info] does get the backtrace associated to info *)
41
42 val backtrace_to_string : backtrace -> string
43 (** [backtrace_to_string info] does get the backtrace associated to info *)
44
45 val record_backtrace : bool -> unit
46
47 val capture : exn -> iexn
48 (** Add the current backtrace information and other meta-data to the
49 given exception.
50
51 The intended use case is to re-raise an exception while preserving
52 the meta-data:
53 {[
54
55 try foo
56 with
57 | Bar -> bar
58 | My_exn _ as exn ->
59 let (exn, info) = Exninfo.capture err in
60 ...
61 let info = ... in
62 Exninfo.iraise (exn, info)
63
64 | exn when CErrors.noncritical exn ->
65 let iexn = Exninfo.capture err in
66 ...
67 Exninfo.iraise iexn
68
69 ]}
70
71 where [baz] should re-raise using [iraise] below.
72
73 WARNING: any intermediate code between the [with] and the handler may
74 modify the backtrace. Yes, that includes [when] clauses. Ideally, what you
75 should do is something like:
76 {[
77
78 try foo
79 with exn when CErrors.noncritical exn ->
80 let (err, info) = Exninfo.capture exn in
81 match err with
82 | exception Bar -> ...
83 | err -> ...
84
85 ]}
86
87 I admit that's a bit heavy, but there is not much to do...
88
89 *)
90
91 val iraise : iexn -> 'a
92 (** Raise the given enriched exception. *)
93
94 val reify : unit -> info