Import Upstream version 20180207
[hcoop/debian/mlton.git] / doc / guide / src / MLtonExn.adoc
CommitLineData
7f918cf1
CE
1MLtonExn
2========
3
4[source,sml]
5----
6signature MLTON_EXN =
7 sig
8 val addExnMessager: (exn -> string option) -> unit
9 val history: exn -> string list
10
11 val defaultTopLevelHandler: exn -> 'a
12 val getTopLevelHandler: unit -> (exn -> unit)
13 val setTopLevelHandler: (exn -> unit) -> unit
14 val topLevelHandler: exn -> 'a
15 end
16----
17
18* `addExnMessager f`
19+
20adds `f` as a pretty-printer to be used by `General.exnMessage` for
21converting exceptions to strings. Messagers are tried in order from
22most recently added to least recently added.
23
24* `history e`
25+
26returns call stack at the point that `e` was first raised. Each
27element of the list is a file position. The elements are in reverse
28chronological order, i.e. the function called last is at the front of
29the list.
30+
31`history e` will return `[]` unless the program is compiled with
32`-const 'Exn.keepHistory true'`.
33
34* `defaultTopLevelHandler e`
35+
36function that behaves as the default top level handler; that is, print
37out the unhandled exception message for `e` and exit.
38
39* `getTopLevelHandler ()`
40+
41get the top level handler.
42
43* `setTopLevelHandler f`
44+
45set the top level handler to the function `f`. The function `f`
46should not raise an exception or return normally.
47
48* `topLevelHandler e`
49+
50behaves as if the top level handler received the exception `e`.