moonpool/dev/ocaml/Stdlib/Printexc/index.html

18 lines
No EOL
27 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"><head><title>Printexc (ocaml.Stdlib.Printexc)</title><link rel="stylesheet" href="../../../_odoc-theme/odoc.css"/><meta charset="utf-8"/><meta name="generator" content="odoc 2.2.1"/><meta name="viewport" content="width=device-width,initial-scale=1.0"/><script src="../../../highlight.pack.js"></script><script>hljs.initHighlightingOnLoad();</script></head><body class="odoc"><nav class="odoc-nav"><a href="../index.html">Up</a> <a href="../../index.html">ocaml</a> &#x00BB; <a href="../index.html">Stdlib</a> &#x00BB; Printexc</nav><header class="odoc-preamble"><h1>Module <code><span>Stdlib.Printexc</span></code></h1><p>Facilities for printing exceptions and inspecting current call stack.</p></header><nav class="odoc-toc"><ul><li><a href="#raw-backtraces">Raw backtraces</a></li><li><a href="#current-call-stack">Current call stack</a></li><li><a href="#uncaught-exceptions">Uncaught exceptions</a></li><li><a href="#manipulation-of-backtrace-information">Manipulation of backtrace information</a></li><li><a href="#raw-backtrace-slots">Raw backtrace slots</a></li><li><a href="#exception-slots">Exception slots</a></li></ul></nav><div class="odoc-content"><div class="odoc-spec"><div class="spec type anchored" id="type-t"><a href="#type-t" class="anchor"></a><code><span><span class="keyword">type</span> t</span><span> = exn</span><span> = </span><span>..</span></code></div><div class="spec-doc"><p>The type of exception values.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-to_string"><a href="#val-to_string" class="anchor"></a><code><span><span class="keyword">val</span> to_string : <span>exn <span class="arrow">&#45;&gt;</span></span> string</span></code></div><div class="spec-doc"><p><code>Printexc.to_string e</code> returns a string representation of the exception <code>e</code>.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-to_string_default"><a href="#val-to_string_default" class="anchor"></a><code><span><span class="keyword">val</span> to_string_default : <span>exn <span class="arrow">&#45;&gt;</span></span> string</span></code></div><div class="spec-doc"><p><code>Printexc.to_string_default e</code> returns a string representation of the exception <code>e</code>, ignoring all registered exception printers.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.09</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-print"><a href="#val-print" class="anchor"></a><code><span><span class="keyword">val</span> print : <span><span>(<span><span class="type-var">'a</span> <span class="arrow">&#45;&gt;</span></span> <span class="type-var">'b</span>)</span> <span class="arrow">&#45;&gt;</span></span> <span><span class="type-var">'a</span> <span class="arrow">&#45;&gt;</span></span> <span class="type-var">'b</span></span></code></div><div class="spec-doc"><p><code>Printexc.print fn x</code> applies <code>fn</code> to <code>x</code> and returns the result. If the evaluation of <code>fn 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><div class="odoc-spec"><div class="spec value anchored" id="val-catch"><a href="#val-catch" class="anchor"></a><code><span><span class="keyword">val</span> catch : <span><span>(<span><span class="type-var">'a</span> <span class="arrow">&#45;&gt;</span></span> <span class="type-var">'b</span>)</span> <span class="arrow">&#45;&gt;</span></span> <span><span class="type-var">'a</span> <span class="arrow">&#45;&gt;</span></span> <span class="type-var">'b</span></span></code></div><div class="spec-doc"><p><code>Printexc.catch fn x</code> is similar to <a href="#val-print"><code>Printexc.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>Printexc.catch</code> does. Moreover, calling <code>Printexc.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>Printexc.catch</code> in new code.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-print_backtrace"><a href="#val-print_backtrace" class="anchor"></a><code><span><span class="keyword">val</span> print_backtrace : <span><a href="../index.html#type-out_channel">out_channel</a> <span class="arrow">&#45;&gt;</span></span> unit</span></code></div><div class="spec-doc"><p><code>Printexc.print_backtrace oc</code> prints an exception backtrace on the output channel <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><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 3.11.0</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-get_backtrace"><a href="#val-get_backtrace" class="anchor"></a><code><span><span class="keyword">val</span> get_backtrace : <span>unit <span class="arrow">&#45;&gt;</span></span> string</span></code></div><div class="spec-doc"><p><code>Printexc.get_backtrace ()</code> returns a string containing the same exception backtrace that <code>Printexc.print_backtrace</code> would print. Same restriction usage than <a href="#val-print_backtrace"><code>print_backtrace</code></a>.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 3.11.0</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-record_backtrace"><a href="#val-record_backtrace" class="anchor"></a><code><span><span class="keyword">val</span> record_backtrace : <span>bool <span class="arrow">&#45;&gt;</span></span> unit</span></code></div><div class="spec-doc"><p><code>Printexc.record_backtrace b</code> turns recording of exception backtraces on (if <code>b = true</code>) or off (if <code>b = false</code>). Initially, backtraces are not recorded, unless the <code>b</code> flag is given to the program through the <code>OCAMLRUNPARAM</code> variable.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 3.11.0</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-backtrace_status"><a href="#val-backtrace_status" class="anchor"></a><code><span><span class="keyword">val</span> backtrace_status : <span>unit <span class="arrow">&#45;&gt;</span></span> bool</span></code></div><div class="spec-doc"><p><code>Printexc.backtrace_status()</code> returns <code>true</code> if exception backtraces are currently recorded, <code>false</code> if not.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 3.11.0</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-register_printer"><a href="#val-register_printer" class="anchor"></a><code><span><span class="keyword">val</span> register_printer : <span><span>(<span>exn <span class="arrow">&#45;&gt;</span></span> <span>string option</span>)</span> <span class="arrow">&#45;&gt;</span></span> unit</span></code></div><div class="spec-doc"><p><code>Printexc.register_printer fn</code> registers <code>fn</code> as an exception printer. The printer should return <code>None</code> or raise an exception if it does not know how to convert the passed exception, and <code>Some
s</code> with <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>Some 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>fn</code> should not use the backtrace if it has itself raised an exception before.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 3.11.2</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-use_printers"><a href="#val-use_printers" class="anchor"></a><code><span><span class="keyword">val</span> use_printers : <span>exn <span class="arrow">&#45;&gt;</span></span> <span>string option</span></span></code></div><div class="spec-doc"><p><code>Printexc.use_printers e</code> returns <code>None</code> if there are no registered printers and <code>Some s</code> with else as the resulting string otherwise.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.09</li></ul></div></div><h2 id="raw-backtraces"><a href="#raw-backtraces" class="anchor"></a>Raw backtraces</h2><div class="odoc-spec"><div class="spec type anchored" id="type-raw_backtrace"><a href="#type-raw_backtrace" class="anchor"></a><code><span><span class="keyword">type</span> raw_backtrace</span></code></div><div class="spec-doc"><p>The type <code>raw_backtrace</code> stores a backtrace in a low-level format, which can be converted to usable form using <code>raw_backtrace_entries</code> and <code>backtrace_slots_of_raw_entry</code> below.</p><p>Converting backtraces to <code>backtrace_slot</code>s is slower than capturing the backtraces. If an application processes many backtraces, it can be useful to use <code>raw_backtrace</code> to avoid or delay conversion.</p><p>Raw backtraces cannot be marshalled. If you need marshalling, you should use the array returned by the <code>backtrace_slots</code> function of the next section.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.01.0</li></ul></div></div><div class="odoc-spec"><div class="spec type anchored" id="type-raw_backtrace_entry"><a href="#type-raw_backtrace_entry" class="anchor"></a><code><span><span class="keyword">type</span> raw_backtrace_entry</span><span> = <span class="keyword">private</span> int</span></code></div><div class="spec-doc"><p>A <code>raw_backtrace_entry</code> is an element of a <code>raw_backtrace</code>.</p><p>Each <code>raw_backtrace_entry</code> is an opaque integer, whose value is not stable between different programs, or even between different runs of the same binary.</p><p>A <code>raw_backtrace_entry</code> can be converted to a usable form using <code>backtrace_slots_of_raw_entry</code> below. Note that, due to inlining, a single <code>raw_backtrace_entry</code> may convert to several <code>backtrace_slot</code>s. Since the values of a <code>raw_backtrace_entry</code> are not stable, they cannot be marshalled. If they are to be converted, the conversion must be done by the process that generated them.</p><p>Again due to inlining, there may be multiple distinct raw_backtrace_entry values that convert to equal <code>backtrace_slot</code>s. However, if two <code>raw_backtrace_entry</code>s are equal as integers, then they represent the same <code>backtrace_slot</code>s.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.12.0</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-raw_backtrace_entries"><a href="#val-raw_backtrace_entries" class="anchor"></a><code><span><span class="keyword">val</span> raw_backtrace_entries : <span><a href="#type-raw_backtrace">raw_backtrace</a> <span class="arrow">&#45;&gt;</span></span> <span><a href="#type-raw_backtrace_entry">raw_backtrace_entry</a> array</span></span></code></div><div class="spec-doc"><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.12.0</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-get_raw_backtrace"><a href="#val-get_raw_backtrace" class="anchor"></a><code><span><span class="keyword">val</span> get_raw_backtrace : <span>unit <span class="arrow">&#45;&gt;</span></span> <a href="#type-raw_backtrace">raw_backtrace</a></span></code></div><div class="spec-doc"><p><code>Printexc.get_raw_backtrace ()</code> returns the same exception backtrace that <code>Printexc.print_backtrace</code> would print, but in a raw format. Same restriction usage than <a href="#val-print_backtrace"><code>print_backtrace</code></a>.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.01.0</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-print_raw_backtrace"><a href="#val-print_raw_backtrace" class="anchor"></a><code><span><span class="keyword">val</span> print_raw_backtrace : <span><a href="../index.html#type-out_channel">out_channel</a> <span class="arrow">&#45;&gt;</span></span> <span><a href="#type-raw_backtrace">raw_backtrace</a> <span class="arrow">&#45;&gt;</span></span> unit</span></code></div><div class="spec-doc"><p>Print a raw backtrace in the same format <code>Printexc.print_backtrace</code> uses.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.01.0</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-raw_backtrace_to_string"><a href="#val-raw_backtrace_to_string" class="anchor"></a><code><span><span class="keyword">val</span> raw_backtrace_to_string : <span><a href="#type-raw_backtrace">raw_backtrace</a> <span class="arrow">&#45;&gt;</span></span> string</span></code></div><div class="spec-doc"><p>Return a string from a raw backtrace, in the same format <code>Printexc.get_backtrace</code> uses.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.01.0</li></ul></div></div><div class="odoc-spec"><div class="spec value external anchored" id="val-raise_with_backtrace"><a href="#val-raise_with_backtrace" class="anchor"></a><code><span><span class="keyword">val</span> raise_with_backtrace : <span>exn <span class="arrow">&#45;&gt;</span></span> <span><a href="#type-raw_backtrace">raw_backtrace</a> <span class="arrow">&#45;&gt;</span></span> <span class="type-var">'a</span></span></code></div><div class="spec-doc"><p>Reraise the exception using the given raw_backtrace for the origin of the exception</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.05.0</li></ul></div></div><h2 id="current-call-stack"><a href="#current-call-stack" class="anchor"></a>Current call stack</h2><div class="odoc-spec"><div class="spec value external anchored" id="val-get_callstack"><a href="#val-get_callstack" class="anchor"></a><code><span><span class="keyword">val</span> get_callstack : <span>int <span class="arrow">&#45;&gt;</span></span> <a href="#type-raw_backtrace">raw_backtrace</a></span></code></div><div class="spec-doc"><p><code>Printexc.get_callstack 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>n</code> entries. (Note: this function is not related to exceptions at all, despite being part of the <code>Printexc</code> module.)</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.01.0</li></ul></div></div><h2 id="uncaught-exceptions"><a href="#uncaught-exceptions" class="anchor"></a>Uncaught exceptions</h2><div class="odoc-spec"><div class="spec value anchored" id="val-default_uncaught_exception_handler"><a href="#val-default_uncaught_exception_handler" class="anchor"></a><code><span><span class="keyword">val</span> default_uncaught_exception_handler : <span>exn <span class="arrow">&#45;&gt;</span></span> <span><a href="#type-raw_backtrace">raw_backtrace</a> <span class="arrow">&#45;&gt;</span></span> unit</span></code></div><div class="spec-doc"><p><code>Printexc.default_uncaught_exception_handler</code> prints the exception and backtrace on standard error output.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.11</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-set_uncaught_exception_handler"><a href="#val-set_uncaught_exception_handler" class="anchor"></a><code><span><span class="keyword">val</span> set_uncaught_exception_handler : <span><span>(<span>exn <span class="arrow">&#45;&gt;</span></span> <span><a href="#type-raw_backtrace">raw_backtrace</a> <span class="arrow">&#45;&gt;</span></span> unit)</span> <span class="arrow">&#45;&gt;</span></span> unit</span></code></div><div class="spec-doc"><p><code>Printexc.set_uncaught_exception_handler fn</code> registers <code>fn</code> as the handler for uncaught exceptions. The default handler is <a href="#val-default_uncaught_exception_handler"><code>Printexc.default_uncaught_exception_handler</code></a>.</p><p>Note that when <code>fn</code> is called all the functions registered with <a href="../index.html#val-at_exit"><code>Stdlib.at_exit</code></a> have already been called. Because of this you must make sure any output channel <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>fn</code> raises an exception, both the exceptions passed to <code>fn</code> and raised by <code>fn</code> will be printed with their respective backtrace.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.02.0</li></ul></div></div><h2 id="manipulation-of-backtrace-information"><a href="#manipulation-of-backtrace-information" class="anchor"></a>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><div class="odoc-spec"><div class="spec type anchored" id="type-backtrace_slot"><a href="#type-backtrace_slot" class="anchor"></a><code><span><span class="keyword">type</span> backtrace_slot</span></code></div><div class="spec-doc"><p>The abstract type <code>backtrace_slot</code> represents a single slot of a backtrace.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.02</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-backtrace_slots"><a href="#val-backtrace_slots" class="anchor"></a><code><span><span class="keyword">val</span> backtrace_slots : <span><a href="#type-raw_backtrace">raw_backtrace</a> <span class="arrow">&#45;&gt;</span></span> <span><span><a href="#type-backtrace_slot">backtrace_slot</a> array</span> option</span></span></code></div><div class="spec-doc"><p>Returns the slots of a raw backtrace, or <code>None</code> if none of them contain useful information.</p><p>In the return array, the slot at index <code>0</code> corresponds to the most recent function call, raise, or primitive <code>get_backtrace</code> call in the trace.</p><p>Some possible reasons for returning <code>None</code> are as follow:</p><ul><li>none of the slots in the trace come from modules compiled with debug information (<code>-g</code>)</li><li>the program is a bytecode program that has not been linked with debug information enabled (<code>ocamlc -g</code>)</li></ul><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.02.0</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-backtrace_slots_of_raw_entry"><a href="#val-backtrace_slots_of_raw_entry" class="anchor"></a><code><span><span class="keyword">val</span> backtrace_slots_of_raw_entry :
<span><a href="#type-raw_backtrace_entry">raw_backtrace_entry</a> <span class="arrow">&#45;&gt;</span></span>
<span><span><a href="#type-backtrace_slot">backtrace_slot</a> array</span> option</span></span></code></div><div class="spec-doc"><p>Returns the slots of a single raw backtrace entry, or <code>None</code> if this entry lacks debug information.</p><p>Slots are returned in the same order as <code>backtrace_slots</code>: the slot at index <code>0</code> is the most recent call, raise, or primitive, and subsequent slots represent callers.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.12</li></ul></div></div><div class="odoc-spec"><div class="spec type anchored" id="type-location"><a href="#type-location" class="anchor"></a><code><span><span class="keyword">type</span> location</span><span> = </span><span>{</span></code><ol><li id="type-location.filename" class="def record field anchored"><a href="#type-location.filename" class="anchor"></a><code><span>filename : string;</span></code></li><li id="type-location.line_number" class="def record field anchored"><a href="#type-location.line_number" class="anchor"></a><code><span>line_number : int;</span></code></li><li id="type-location.start_char" class="def record field anchored"><a href="#type-location.start_char" class="anchor"></a><code><span>start_char : int;</span></code></li><li id="type-location.end_char" class="def record field anchored"><a href="#type-location.end_char" class="anchor"></a><code><span>end_char : int;</span></code></li></ol><code><span>}</span></code></div><div class="spec-doc"><p>The type of location information found in backtraces. <code>start_char</code> and <code>end_char</code> are positions relative to the beginning of the line.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.02</li></ul></div></div><div class="odoc-spec"><div class="spec module anchored" id="module-Slot"><a href="#module-Slot" class="anchor"></a><code><span><span class="keyword">module</span> <a href="Slot/index.html">Slot</a></span><span> : <span class="keyword">sig</span> ... <span class="keyword">end</span></span></code></div></div><h2 id="raw-backtrace-slots"><a href="#raw-backtrace-slots" class="anchor"></a>Raw backtrace slots</h2><div class="odoc-spec"><div class="spec type anchored" id="type-raw_backtrace_slot"><a href="#type-raw_backtrace_slot" class="anchor"></a><code><span><span class="keyword">type</span> raw_backtrace_slot</span></code></div><div class="spec-doc"><p>This type is used to iterate over the slots of a <code>raw_backtrace</code>. For most purposes, <code>backtrace_slots_of_raw_entry</code> is easier to use.</p><p>Like <code>raw_backtrace_entry</code>, values of this type are process-specific and 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><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.02.0</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-raw_backtrace_length"><a href="#val-raw_backtrace_length" class="anchor"></a><code><span><span class="keyword">val</span> raw_backtrace_length : <span><a href="#type-raw_backtrace">raw_backtrace</a> <span class="arrow">&#45;&gt;</span></span> int</span></code></div><div class="spec-doc"><p><code>raw_backtrace_length bckt</code> returns the number of slots in the backtrace <code>bckt</code>.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.02</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-get_raw_backtrace_slot"><a href="#val-get_raw_backtrace_slot" class="anchor"></a><code><span><span class="keyword">val</span> get_raw_backtrace_slot : <span><a href="#type-raw_backtrace">raw_backtrace</a> <span class="arrow">&#45;&gt;</span></span> <span>int <span class="arrow">&#45;&gt;</span></span> <a href="#type-raw_backtrace_slot">raw_backtrace_slot</a></span></code></div><div class="spec-doc"><p><code>get_raw_backtrace_slot bckt pos</code> returns the slot in position <code>pos</code> in the backtrace <code>bckt</code>.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.02</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-convert_raw_backtrace_slot"><a href="#val-convert_raw_backtrace_slot" class="anchor"></a><code><span><span class="keyword">val</span> convert_raw_backtrace_slot : <span><a href="#type-raw_backtrace_slot">raw_backtrace_slot</a> <span class="arrow">&#45;&gt;</span></span> <a href="#type-backtrace_slot">backtrace_slot</a></span></code></div><div class="spec-doc"><p>Extracts the user-friendly <code>backtrace_slot</code> from a low-level <code>raw_backtrace_slot</code>.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.02</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-get_raw_backtrace_next_slot"><a href="#val-get_raw_backtrace_next_slot" class="anchor"></a><code><span><span class="keyword">val</span> get_raw_backtrace_next_slot :
<span><a href="#type-raw_backtrace_slot">raw_backtrace_slot</a> <span class="arrow">&#45;&gt;</span></span>
<span><a href="#type-raw_backtrace_slot">raw_backtrace_slot</a> option</span></span></code></div><div class="spec-doc"><p><code>get_raw_backtrace_next_slot 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="language-ocaml"><code>(* Iterate over inlined frames *)
let rec iter_raw_backtrace_slot f slot =
f slot;
match get_raw_backtrace_next_slot slot with
| None -&gt; ()
| Some slot' -&gt; iter_raw_backtrace_slot f slot'
(* Iterate over stack frames *)
let iter_raw_backtrace f bt =
for i = 0 to raw_backtrace_length bt - 1 do
iter_raw_backtrace_slot f (get_raw_backtrace_slot bt i)
done</code></pre><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.04.0</li></ul></div></div><h2 id="exception-slots"><a href="#exception-slots" class="anchor"></a>Exception slots</h2><div class="odoc-spec"><div class="spec value anchored" id="val-exn_slot_id"><a href="#val-exn_slot_id" class="anchor"></a><code><span><span class="keyword">val</span> exn_slot_id : <span>exn <span class="arrow">&#45;&gt;</span></span> int</span></code></div><div class="spec-doc"><p><code>Printexc.exn_slot_id</code> returns an integer which uniquely identifies the constructor used to create the exception value <code>exn</code> (in the current runtime).</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.02.0</li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-exn_slot_name"><a href="#val-exn_slot_name" class="anchor"></a><code><span><span class="keyword">val</span> exn_slot_name : <span>exn <span class="arrow">&#45;&gt;</span></span> string</span></code></div><div class="spec-doc"><p><code>Printexc.exn_slot_name exn</code> returns the internal name of the constructor used to create the exception value <code>exn</code>.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.02.0</li></ul></div></div></div></body></html>