tur/panic
inspect panics recovered by catch-unwind.
(catch-unwind thunk) returns a Result whose err slot carries an opaque Panic handle (a boxed tur_panic_payload). This module wraps that handle in a (defopaque Panic) newtype and exposes accessors for the panic message, source file, source line, and payload TypeKind tag, so callers never have to dereference the raw pointer themselves.
Typical use:
(let [r (catch-unwind (fn [] :int (risky)))]
(if (err? r)
(println (panic-message (result-panic r)))
(use (ok-val r))))
Compiled, the accessors call the tur_panic_payload_* helpers emitted into every program's C preamble (Phase R2); a program that never catches a panic still links cleanly. Under --interpret the same names are natives over the interpreter's own panic payload (eval.c), so both engines answer alike: the message, the base name of the source file, the line and the payload's type.
Since: Phase R2
Panic
(defopaque Panic :ptr<void>)
result-panic
(result-panic [r :int] :Panic)
extract the Panic handle from a caught (err ...) result.
| r | the :int result box returned by catch-unwind / catch-panic-of |
The opaque Panic handle from the err slot (0 when r is ok).
(let [r (catch-unwind (fn [] :int (panic "boom")))] (panic-message (result-panic r))) ; => "boom"
Since: Phase R2
panic-message
(panic-message [p :Panic] :cstr)
the message string carried by a caught Panic.
| p | a Panic handle (see result-panic) |
The panic message for a string panic, or "" when none is available.
Since: Phase R2
panic-file
(panic-file [p :Panic] :cstr)
source file of the panic call site.
| p | a Panic handle |
The source file path, or "" when unknown.
Since: Phase R2
panic-line
(panic-line [p :Panic] :int)
source line of the panic call site.
| p | a Panic handle |
The source line, or 0 when unknown.
Since: Phase R2
panic-type
(panic-type [p :Panic] :int)
the TypeKind tag of the panic payload.
| p | a Panic handle |
The integer TypeKind of the boxed payload (e.g. the tag for :cstr for a plain string panic), or 0 when unknown.
Since: Phase R2