File: Stdlib.Printexc.html

package info (click to toggle)
ocaml-doc 4.11-2
  • links: PTS, VCS
  • area: non-free
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 20,580 kB
  • sloc: sh: 37; makefile: 11
file content (517 lines) | stat: -rw-r--r-- 28,049 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<link rel="stylesheet" href="style.css" type="text/css">
<meta content="text/html; charset=iso-8859-1" http-equiv="Content-Type">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="Start" href="index.html">
<link rel="previous" href="Stdlib.Pervasives.html">
<link rel="next" href="Stdlib.Printf.html">
<link rel="Up" href="Stdlib.html">
<link title="Index of types" rel=Appendix href="index_types.html">
<link title="Index of extensions" rel=Appendix href="index_extensions.html">
<link title="Index of exceptions" rel=Appendix href="index_exceptions.html">
<link title="Index of values" rel=Appendix href="index_values.html">
<link title="Index of modules" rel=Appendix href="index_modules.html">
<link title="Index of module types" rel=Appendix href="index_module_types.html">
<link title="Arg" rel="Chapter" href="Arg.html">
<link title="Array" rel="Chapter" href="Array.html">
<link title="ArrayLabels" rel="Chapter" href="ArrayLabels.html">
<link title="Bigarray" rel="Chapter" href="Bigarray.html">
<link title="Bool" rel="Chapter" href="Bool.html">
<link title="Buffer" rel="Chapter" href="Buffer.html">
<link title="Bytes" rel="Chapter" href="Bytes.html">
<link title="BytesLabels" rel="Chapter" href="BytesLabels.html">
<link title="Callback" rel="Chapter" href="Callback.html">
<link title="CamlinternalFormat" rel="Chapter" href="CamlinternalFormat.html">
<link title="CamlinternalFormatBasics" rel="Chapter" href="CamlinternalFormatBasics.html">
<link title="CamlinternalLazy" rel="Chapter" href="CamlinternalLazy.html">
<link title="CamlinternalMod" rel="Chapter" href="CamlinternalMod.html">
<link title="CamlinternalOO" rel="Chapter" href="CamlinternalOO.html">
<link title="Char" rel="Chapter" href="Char.html">
<link title="Complex" rel="Chapter" href="Complex.html">
<link title="Condition" rel="Chapter" href="Condition.html">
<link title="Digest" rel="Chapter" href="Digest.html">
<link title="Dynlink" rel="Chapter" href="Dynlink.html">
<link title="Ephemeron" rel="Chapter" href="Ephemeron.html">
<link title="Event" rel="Chapter" href="Event.html">
<link title="Filename" rel="Chapter" href="Filename.html">
<link title="Float" rel="Chapter" href="Float.html">
<link title="Format" rel="Chapter" href="Format.html">
<link title="Fun" rel="Chapter" href="Fun.html">
<link title="Gc" rel="Chapter" href="Gc.html">
<link title="Genlex" rel="Chapter" href="Genlex.html">
<link title="Hashtbl" rel="Chapter" href="Hashtbl.html">
<link title="Int" rel="Chapter" href="Int.html">
<link title="Int32" rel="Chapter" href="Int32.html">
<link title="Int64" rel="Chapter" href="Int64.html">
<link title="Lazy" rel="Chapter" href="Lazy.html">
<link title="Lexing" rel="Chapter" href="Lexing.html">
<link title="List" rel="Chapter" href="List.html">
<link title="ListLabels" rel="Chapter" href="ListLabels.html">
<link title="Map" rel="Chapter" href="Map.html">
<link title="Marshal" rel="Chapter" href="Marshal.html">
<link title="MoreLabels" rel="Chapter" href="MoreLabels.html">
<link title="Mutex" rel="Chapter" href="Mutex.html">
<link title="Nativeint" rel="Chapter" href="Nativeint.html">
<link title="Obj" rel="Chapter" href="Obj.html">
<link title="Ocaml_operators" rel="Chapter" href="Ocaml_operators.html">
<link title="Oo" rel="Chapter" href="Oo.html">
<link title="Option" rel="Chapter" href="Option.html">
<link title="Parsing" rel="Chapter" href="Parsing.html">
<link title="Printexc" rel="Chapter" href="Printexc.html">
<link title="Printf" rel="Chapter" href="Printf.html">
<link title="Queue" rel="Chapter" href="Queue.html">
<link title="Random" rel="Chapter" href="Random.html">
<link title="Result" rel="Chapter" href="Result.html">
<link title="Scanf" rel="Chapter" href="Scanf.html">
<link title="Seq" rel="Chapter" href="Seq.html">
<link title="Set" rel="Chapter" href="Set.html">
<link title="Spacetime" rel="Chapter" href="Spacetime.html">
<link title="Stack" rel="Chapter" href="Stack.html">
<link title="StdLabels" rel="Chapter" href="StdLabels.html">
<link title="Stdlib" rel="Chapter" href="Stdlib.html">
<link title="Str" rel="Chapter" href="Str.html">
<link title="Stream" rel="Chapter" href="Stream.html">
<link title="String" rel="Chapter" href="String.html">
<link title="StringLabels" rel="Chapter" href="StringLabels.html">
<link title="Sys" rel="Chapter" href="Sys.html">
<link title="Thread" rel="Chapter" href="Thread.html">
<link title="ThreadUnix" rel="Chapter" href="ThreadUnix.html">
<link title="Uchar" rel="Chapter" href="Uchar.html">
<link title="Unit" rel="Chapter" href="Unit.html">
<link title="Unix" rel="Chapter" href="Unix.html">
<link title="UnixLabels" rel="Chapter" href="UnixLabels.html">
<link title="Weak" rel="Chapter" href="Weak.html"><link title="Raw backtraces" rel="Section" href="#1_Rawbacktraces">
<link title="Current call stack" rel="Section" href="#1_Currentcallstack">
<link title="Uncaught exceptions" rel="Section" href="#1_Uncaughtexceptions">
<link title="Manipulation of backtrace information" rel="Section" href="#1_Manipulationofbacktraceinformation">
<link title="Raw backtrace slots" rel="Section" href="#1_Rawbacktraceslots">
<link title="Exception slots" rel="Section" href="#1_Exceptionslots">
<title>Stdlib.Printexc</title>
</head>
<body>
<div class="navbar"><a class="pre" href="Stdlib.Pervasives.html" title="Stdlib.Pervasives">Previous</a>
&nbsp;<a class="up" href="Stdlib.html" title="Stdlib">Up</a>
&nbsp;<a class="post" href="Stdlib.Printf.html" title="Stdlib.Printf">Next</a>
</div>
<h1>Module <a href="type_Stdlib.Printexc.html">Stdlib.Printexc</a></h1>

<pre><span id="MODULEPrintexc"><span class="keyword">module</span> Printexc</span>: <code class="type"><a href="Printexc.html">Printexc</a></code></pre><hr width="100%">

<pre><span id="TYPEt"><span class="keyword">type</span> <code class="type"></code>t</span> = <code class="type">exn</code> = ..</pre>
<div class="info ">
<div class="info-desc">
<p>The type of exception values.</p>
</div>
</div>


<pre><span id="VALto_string"><span class="keyword">val</span> to_string</span> : <code class="type">exn -> string</code></pre><div class="info ">
<div class="info-desc">
<p><code class="code"><span class="constructor">Printexc</span>.to_string&nbsp;e</code> returns a string representation of
   the exception <code class="code">e</code>.</p>
</div>
</div>

<pre><span id="VALto_string_default"><span class="keyword">val</span> to_string_default</span> : <code class="type">exn -> string</code></pre><div class="info ">
<div class="info-desc">
<p><code class="code"><span class="constructor">Printexc</span>.to_string_default&nbsp;e</code> returns a string representation of the
    exception <code class="code">e</code>, ignoring all registered exception printers.</p>
</div>
<ul class="info-attributes">
<li><b>Since</b> 4.09</li>
</ul>
</div>

<pre><span id="VALprint"><span class="keyword">val</span> print</span> : <code class="type">('a -> 'b) -> 'a -> 'b</code></pre><div class="info ">
<div class="info-desc">
<p><code class="code"><span class="constructor">Printexc</span>.print&nbsp;fn&nbsp;x</code> applies <code class="code">fn</code> to <code class="code">x</code> and returns the result.
   If the evaluation of <code class="code">fn&nbsp;x</code> raises any exception, the
   name of the exception is printed on standard error output,
   and the exception is raised again.
   The typical use is to catch and report exceptions that
   escape a function application.</p>
</div>
</div>

<pre><span id="VALcatch"><span class="keyword">val</span> catch</span> : <code class="type">('a -> 'b) -> 'a -> 'b</code></pre><div class="info ">
<div class="info-desc">
<p><code class="code"><span class="constructor">Printexc</span>.catch&nbsp;fn&nbsp;x</code> is similar to <a href="Printexc.html#VALprint"><code class="code"><span class="constructor">Printexc</span>.print</code></a>, but
   aborts the program with exit code 2 after printing the
   uncaught exception.  This function is deprecated: the runtime
   system is now able to print uncaught exceptions as precisely
   as <code class="code"><span class="constructor">Printexc</span>.catch</code> does.  Moreover, calling <code class="code"><span class="constructor">Printexc</span>.catch</code>
   makes it harder to track the location of the exception
   using the debugger or the stack backtrace facility.
   So, do not use <code class="code"><span class="constructor">Printexc</span>.catch</code> in new code.</p>
</div>
</div>

<pre><span id="VALprint_backtrace"><span class="keyword">val</span> print_backtrace</span> : <code class="type"><a href="Stdlib.html#TYPEout_channel">out_channel</a> -> unit</code></pre><div class="info ">
<div class="info-desc">
<p><code class="code"><span class="constructor">Printexc</span>.print_backtrace&nbsp;oc</code> prints an exception backtrace
    on the output channel <code class="code">oc</code>.  The backtrace lists the program
    locations where the most-recently raised exception was raised
    and where it was propagated through function calls.</p>

<p>If the call is not inside an exception handler, the returned
    backtrace is unspecified. If the call is after some
    exception-catching code (before in the handler, or in a when-guard
    during the matching of the exception handler), the backtrace may
    correspond to a later exception than the handled one.</p>
</div>
<ul class="info-attributes">
<li><b>Since</b> 3.11.0</li>
</ul>
</div>

<pre><span id="VALget_backtrace"><span class="keyword">val</span> get_backtrace</span> : <code class="type">unit -> string</code></pre><div class="info ">
<div class="info-desc">
<p><code class="code"><span class="constructor">Printexc</span>.get_backtrace&nbsp;()</code> returns a string containing the
    same exception backtrace that <code class="code"><span class="constructor">Printexc</span>.print_backtrace</code> would
    print. Same restriction usage than <a href="Printexc.html#VALprint_backtrace"><code class="code"><span class="constructor">Printexc</span>.print_backtrace</code></a>.</p>
</div>
<ul class="info-attributes">
<li><b>Since</b> 3.11.0</li>
</ul>
</div>

<pre><span id="VALrecord_backtrace"><span class="keyword">val</span> record_backtrace</span> : <code class="type">bool -> unit</code></pre><div class="info ">
<div class="info-desc">
<p><code class="code"><span class="constructor">Printexc</span>.record_backtrace&nbsp;b</code> turns recording of exception backtraces
    on (if <code class="code">b&nbsp;=&nbsp;<span class="keyword">true</span></code>) or off (if <code class="code">b&nbsp;=&nbsp;<span class="keyword">false</span></code>).  Initially, backtraces
    are not recorded, unless the <code class="code">b</code> flag is given to the program
    through the <code class="code"><span class="constructor">OCAMLRUNPARAM</span></code> variable.</p>
</div>
<ul class="info-attributes">
<li><b>Since</b> 3.11.0</li>
</ul>
</div>

<pre><span id="VALbacktrace_status"><span class="keyword">val</span> backtrace_status</span> : <code class="type">unit -> bool</code></pre><div class="info ">
<div class="info-desc">
<p><code class="code"><span class="constructor">Printexc</span>.backtrace_status()</code> returns <code class="code"><span class="keyword">true</span></code> if exception
    backtraces are currently recorded, <code class="code"><span class="keyword">false</span></code> if not.</p>
</div>
<ul class="info-attributes">
<li><b>Since</b> 3.11.0</li>
</ul>
</div>

<pre><span id="VALregister_printer"><span class="keyword">val</span> register_printer</span> : <code class="type">(exn -> string option) -> unit</code></pre><div class="info ">
<div class="info-desc">
<p><code class="code"><span class="constructor">Printexc</span>.register_printer&nbsp;fn</code> registers <code class="code">fn</code> as an exception
    printer.  The printer should return <code class="code"><span class="constructor">None</span></code> or raise an exception
    if it does not know how to convert the passed exception, and <code class="code"><span class="constructor">Some</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;s</code> with <code class="code">s</code> the resulting string if it can convert the passed
    exception. Exceptions raised by the printer are ignored.</p>

<p>When converting an exception into a string, the printers will be invoked
    in the reverse order of their registrations, until a printer returns
    a <code class="code"><span class="constructor">Some</span>&nbsp;s</code> value (if no such printer exists, the runtime will use a
    generic printer).</p>

<p>When using this mechanism, one should be aware that an exception backtrace
    is attached to the thread that saw it raised, rather than to the exception
    itself. Practically, it means that the code related to <code class="code">fn</code> should not use
    the backtrace if it has itself raised an exception before.</p>
</div>
<ul class="info-attributes">
<li><b>Since</b> 3.11.2</li>
</ul>
</div>

<pre><span id="VALuse_printers"><span class="keyword">val</span> use_printers</span> : <code class="type">exn -> string option</code></pre><div class="info ">
<div class="info-desc">
<p><code class="code"><span class="constructor">Printexc</span>.use_printers&nbsp;e</code> returns <code class="code"><span class="constructor">None</span></code> if there are no registered
    printers and <code class="code"><span class="constructor">Some</span>&nbsp;s</code> with else as the resulting string otherwise.</p>
</div>
<ul class="info-attributes">
<li><b>Since</b> 4.09</li>
</ul>
</div>
<h2 id="1_Rawbacktraces">Raw backtraces</h2>
<pre><span id="TYPEraw_backtrace"><span class="keyword">type</span> <code class="type"></code>raw_backtrace</span> </pre>
<div class="info ">
<div class="info-desc">
<p>The abstract type <code class="code">raw_backtrace</code> stores a backtrace in
    a low-level format, instead of directly exposing them as string as
    the <code class="code">get_backtrace()</code> function does.</p>

<p>This allows delaying the formatting of backtraces to when they are
    actually printed, which may be useful if you record more
    backtraces than you print.</p>

<p>Raw backtraces cannot be marshalled. If you need marshalling, you
    should use the array returned by the <code class="code">backtrace_slots</code> function of
    the next section.</p>
</div>
<ul class="info-attributes">
<li><b>Since</b> 4.01.0</li>
</ul>
</div>


<pre><span id="VALget_raw_backtrace"><span class="keyword">val</span> get_raw_backtrace</span> : <code class="type">unit -> <a href="Printexc.html#TYPEraw_backtrace">raw_backtrace</a></code></pre><div class="info ">
<div class="info-desc">
<p><code class="code"><span class="constructor">Printexc</span>.get_raw_backtrace&nbsp;()</code> returns the same exception
    backtrace that <code class="code"><span class="constructor">Printexc</span>.print_backtrace</code> would print, but in
    a raw format. Same restriction usage than <a href="Printexc.html#VALprint_backtrace"><code class="code"><span class="constructor">Printexc</span>.print_backtrace</code></a>.</p>
</div>
<ul class="info-attributes">
<li><b>Since</b> 4.01.0</li>
</ul>
</div>

<pre><span id="VALprint_raw_backtrace"><span class="keyword">val</span> print_raw_backtrace</span> : <code class="type"><a href="Stdlib.html#TYPEout_channel">out_channel</a> -> <a href="Printexc.html#TYPEraw_backtrace">raw_backtrace</a> -> unit</code></pre><div class="info ">
<div class="info-desc">
<p>Print a raw backtrace in the same format
    <code class="code"><span class="constructor">Printexc</span>.print_backtrace</code> uses.</p>
</div>
<ul class="info-attributes">
<li><b>Since</b> 4.01.0</li>
</ul>
</div>

<pre><span id="VALraw_backtrace_to_string"><span class="keyword">val</span> raw_backtrace_to_string</span> : <code class="type"><a href="Printexc.html#TYPEraw_backtrace">raw_backtrace</a> -> string</code></pre><div class="info ">
<div class="info-desc">
<p>Return a string from a raw backtrace, in the same format
    <code class="code"><span class="constructor">Printexc</span>.get_backtrace</code> uses.</p>
</div>
<ul class="info-attributes">
<li><b>Since</b> 4.01.0</li>
</ul>
</div>

<pre><span id="VALraise_with_backtrace"><span class="keyword">val</span> raise_with_backtrace</span> : <code class="type">exn -> <a href="Printexc.html#TYPEraw_backtrace">raw_backtrace</a> -> 'a</code></pre><div class="info ">
<div class="info-desc">
<p>Reraise the exception using the given raw_backtrace for the
    origin of the exception</p>
</div>
<ul class="info-attributes">
<li><b>Since</b> 4.05.0</li>
</ul>
</div>
<h2 id="1_Currentcallstack">Current call stack</h2>
<pre><span id="VALget_callstack"><span class="keyword">val</span> get_callstack</span> : <code class="type">int -> <a href="Printexc.html#TYPEraw_backtrace">raw_backtrace</a></code></pre><div class="info ">
<div class="info-desc">
<p><code class="code"><span class="constructor">Printexc</span>.get_callstack&nbsp;n</code> returns a description of the top of the
    call stack on the current program point (for the current thread),
    with at most <code class="code">n</code> entries.  (Note: this function is not related to
    exceptions at all, despite being part of the <code class="code"><span class="constructor">Printexc</span></code> module.)</p>
</div>
<ul class="info-attributes">
<li><b>Since</b> 4.01.0</li>
</ul>
</div>
<h2 id="1_Uncaughtexceptions">Uncaught exceptions</h2>
<pre><span id="VALdefault_uncaught_exception_handler"><span class="keyword">val</span> default_uncaught_exception_handler</span> : <code class="type">exn -> <a href="Printexc.html#TYPEraw_backtrace">raw_backtrace</a> -> unit</code></pre><div class="info ">
<div class="info-desc">
<p><code class="code"><span class="constructor">Printexc</span>.default_uncaught_exception_handler</code> prints the exception and
    backtrace on standard error output.</p>
</div>
<ul class="info-attributes">
<li><b>Since</b> 4.11</li>
</ul>
</div>

<pre><span id="VALset_uncaught_exception_handler"><span class="keyword">val</span> set_uncaught_exception_handler</span> : <code class="type">(exn -> <a href="Printexc.html#TYPEraw_backtrace">raw_backtrace</a> -> unit) -> unit</code></pre><div class="info ">
<div class="info-desc">
<p><code class="code"><span class="constructor">Printexc</span>.set_uncaught_exception_handler&nbsp;fn</code> registers <code class="code">fn</code> as the handler
    for uncaught exceptions. The default handler is
    <a href="Printexc.html#VALdefault_uncaught_exception_handler"><code class="code"><span class="constructor">Printexc</span>.default_uncaught_exception_handler</code></a>.</p>

<p>Note that when <code class="code">fn</code> is called all the functions registered with
    <a href="Stdlib.html#VALat_exit"><code class="code">at_exit</code></a> have already been called. Because of this you must
    make sure any output channel <code class="code">fn</code> writes on is flushed.</p>

<p>Also note that exceptions raised by user code in the interactive toplevel
    are not passed to this function as they are caught by the toplevel itself.</p>

<p>If <code class="code">fn</code> raises an exception, both the exceptions passed to <code class="code">fn</code> and raised
    by <code class="code">fn</code> will be printed with their respective backtrace.</p>
</div>
<ul class="info-attributes">
<li><b>Since</b> 4.02.0</li>
</ul>
</div>
<h2 id="1_Manipulationofbacktraceinformation">Manipulation of backtrace information</h2>
<p>These functions are used to traverse the slots of a raw backtrace
    and extract information from them in a programmer-friendly format.</p>

<pre><span id="TYPEbacktrace_slot"><span class="keyword">type</span> <code class="type"></code>backtrace_slot</span> </pre>
<div class="info ">
<div class="info-desc">
<p>The abstract type <code class="code">backtrace_slot</code> represents a single slot of
    a backtrace.</p>
</div>
<ul class="info-attributes">
<li><b>Since</b> 4.02</li>
</ul>
</div>


<pre><span id="VALbacktrace_slots"><span class="keyword">val</span> backtrace_slots</span> : <code class="type"><a href="Printexc.html#TYPEraw_backtrace">raw_backtrace</a> -> <a href="Printexc.html#TYPEbacktrace_slot">backtrace_slot</a> array option</code></pre><div class="info ">
<div class="info-desc">
<p>Returns the slots of a raw backtrace, or <code class="code"><span class="constructor">None</span></code> if none of them
    contain useful information.</p>

<p>In the return array, the slot at index <code class="code">0</code> corresponds to the most
    recent function call, raise, or primitive <code class="code">get_backtrace</code> call in
    the trace.</p>

<p>Some possible reasons for returning <code class="code"><span class="constructor">None</span></code> are as follow:</p>
<ul>
<li>none of the slots in the trace come from modules compiled with
    debug information (<code class="code">-g</code>)</li>
<li>the program is a bytecode program that has not been linked with
    debug information enabled (<code class="code">ocamlc&nbsp;-g</code>)</li>
</ul>
</div>
<ul class="info-attributes">
<li><b>Since</b> 4.02.0</li>
</ul>
</div>

<pre><code><span id="TYPElocation"><span class="keyword">type</span> <code class="type"></code>location</span> = {</code></pre><table class="typetable">
<tr>
<td align="left" valign="top" >
<code>&nbsp;&nbsp;</code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTlocation.filename">filename</span>&nbsp;: <code class="type">string</code>;</code></td>

</tr>
<tr>
<td align="left" valign="top" >
<code>&nbsp;&nbsp;</code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTlocation.line_number">line_number</span>&nbsp;: <code class="type">int</code>;</code></td>

</tr>
<tr>
<td align="left" valign="top" >
<code>&nbsp;&nbsp;</code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTlocation.start_char">start_char</span>&nbsp;: <code class="type">int</code>;</code></td>

</tr>
<tr>
<td align="left" valign="top" >
<code>&nbsp;&nbsp;</code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTlocation.end_char">end_char</span>&nbsp;: <code class="type">int</code>;</code></td>

</tr></table>
<code>}</code>

<div class="info ">
<div class="info-desc">
<p>The type of location information found in backtraces. <code class="code">start_char</code>
    and <code class="code">end_char</code> are positions relative to the beginning of the
    line.</p>
</div>
<ul class="info-attributes">
<li><b>Since</b> 4.02</li>
</ul>
</div>


<pre><span id="MODULESlot"><span class="keyword">module</span> <a href="Printexc.Slot.html">Slot</a></span>: <code class="code"><span class="keyword">sig</span></code> <a href="Printexc.Slot.html">..</a> <code class="code"><span class="keyword">end</span></code></pre><div class="info">
</div>
<h2 id="1_Rawbacktraceslots">Raw backtrace slots</h2>
<pre><span id="TYPEraw_backtrace_slot"><span class="keyword">type</span> <code class="type"></code>raw_backtrace_slot</span> </pre>
<div class="info ">
<div class="info-desc">
<p>This type allows direct access to raw backtrace slots, without any
    conversion in an OCaml-usable data-structure. Being
    process-specific, they must absolutely not be marshalled, and are
    unsafe to use for this reason (marshalling them may not fail, but
    un-marshalling and using the result will result in
    undefined behavior).</p>

<p>Elements of this type can still be compared and hashed: when two
    elements are equal, then they represent the same source location
    (the converse is not necessarily true in presence of inlining,
    for example).</p>
</div>
<ul class="info-attributes">
<li><b>Since</b> 4.02.0</li>
</ul>
</div>


<pre><span id="VALraw_backtrace_length"><span class="keyword">val</span> raw_backtrace_length</span> : <code class="type"><a href="Printexc.html#TYPEraw_backtrace">raw_backtrace</a> -> int</code></pre><div class="info ">
<div class="info-desc">
<p><code class="code">raw_backtrace_length&nbsp;bckt</code> returns the number of slots in the
    backtrace <code class="code">bckt</code>.</p>
</div>
<ul class="info-attributes">
<li><b>Since</b> 4.02</li>
</ul>
</div>

<pre><span id="VALget_raw_backtrace_slot"><span class="keyword">val</span> get_raw_backtrace_slot</span> : <code class="type"><a href="Printexc.html#TYPEraw_backtrace">raw_backtrace</a> -> int -> <a href="Printexc.html#TYPEraw_backtrace_slot">raw_backtrace_slot</a></code></pre><div class="info ">
<div class="info-desc">
<p><code class="code">get_raw_backtrace_slot&nbsp;bckt&nbsp;pos</code> returns the slot in position <code class="code">pos</code> in the
    backtrace <code class="code">bckt</code>.</p>
</div>
<ul class="info-attributes">
<li><b>Since</b> 4.02</li>
</ul>
</div>

<pre><span id="VALconvert_raw_backtrace_slot"><span class="keyword">val</span> convert_raw_backtrace_slot</span> : <code class="type"><a href="Printexc.html#TYPEraw_backtrace_slot">raw_backtrace_slot</a> -> <a href="Printexc.html#TYPEbacktrace_slot">backtrace_slot</a></code></pre><div class="info ">
<div class="info-desc">
<p>Extracts the user-friendly <code class="code">backtrace_slot</code> from a low-level
    <code class="code">raw_backtrace_slot</code>.</p>
</div>
<ul class="info-attributes">
<li><b>Since</b> 4.02</li>
</ul>
</div>

<pre><span id="VALget_raw_backtrace_next_slot"><span class="keyword">val</span> get_raw_backtrace_next_slot</span> : <code class="type"><a href="Printexc.html#TYPEraw_backtrace_slot">raw_backtrace_slot</a> -> <a href="Printexc.html#TYPEraw_backtrace_slot">raw_backtrace_slot</a> option</code></pre><div class="info ">
<div class="info-desc">
<p><code class="code">get_raw_backtrace_next_slot&nbsp;slot</code> returns the next slot inlined, if any.</p>

<p>Sample code to iterate over all frames (inlined and non-inlined):</p>
<pre class="codepre"><code class="code">      <span class="comment">(* Iterate over inlined frames *)</span>
      <span class="keyword">let</span> <span class="keyword">rec</span> iter_raw_backtrace_slot f slot =
        f slot;
        <span class="keyword">match</span> get_raw_backtrace_next_slot slot <span class="keyword">with</span>
        <span class="keywordsign">|</span> <span class="constructor">None</span> <span class="keywordsign">-&gt;</span> ()
        <span class="keywordsign">|</span> <span class="constructor">Some</span> slot' <span class="keywordsign">-&gt;</span> iter_raw_backtrace_slot f slot'

      <span class="comment">(* Iterate over stack frames *)</span>
      <span class="keyword">let</span> iter_raw_backtrace f bt =
        <span class="keyword">for</span> i = 0 <span class="keyword">to</span> raw_backtrace_length bt - 1 <span class="keyword">do</span>
          iter_raw_backtrace_slot f (get_raw_backtrace_slot bt i)
        <span class="keyword">done</span>
    </code></pre></div>
<ul class="info-attributes">
<li><b>Since</b> 4.04.0</li>
</ul>
</div>
<h2 id="1_Exceptionslots">Exception slots</h2>
<pre><span id="VALexn_slot_id"><span class="keyword">val</span> exn_slot_id</span> : <code class="type">exn -> int</code></pre><div class="info ">
<div class="info-desc">
<p><code class="code"><span class="constructor">Printexc</span>.exn_slot_id</code> returns an integer which uniquely identifies
    the constructor used to create the exception value <code class="code">exn</code>
    (in the current runtime).</p>
</div>
<ul class="info-attributes">
<li><b>Since</b> 4.02.0</li>
</ul>
</div>

<pre><span id="VALexn_slot_name"><span class="keyword">val</span> exn_slot_name</span> : <code class="type">exn -> string</code></pre><div class="info ">
<div class="info-desc">
<p><code class="code"><span class="constructor">Printexc</span>.exn_slot_name&nbsp;exn</code> returns the internal name of the constructor
    used to create the exception value <code class="code">exn</code>.</p>
</div>
<ul class="info-attributes">
<li><b>Since</b> 4.02.0</li>
</ul>
</div>
</body></html>