How to turn on `exception stack trace` for OCaml `Toplevel`?
Asked Answered
G

2

7

in Toplevel, how to turn on the stack trace for exceptions?

simple question, don't know how to ask more in details.

Gruelling answered 2/3, 2013 at 1:15 Comment(0)
C
10

This used to not be easily possible (only code compiled outside the toplevel would support backtraces), but since OCaml 4.03.0 (released in April 2016) the toplevel supports backtraces, thanks to the contributions of whitequark and Jake Donham.

Just run the toplevel with OCAMLRUNPARAM=b ocaml to get backtraces. Of course, compiled code that you want to link and use from the toplevel should be compiled with -g to contain backtrace information -- otherwise you will only see the part of the call stack that calls functions defined from the toplevel.

Cooler answered 2/3, 2013 at 9:28 Comment(0)
B
1

I know that this question is 10 years old, but here is an answer from 2023: you can use Printexc.record_backtrace true.

Blinnie answered 18/4, 2023 at 21:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.