Jackson Tale
Jackson Tale

Reputation: 25812

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

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

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

Upvotes: 7

Views: 2352

Answers (2)

aqjune
aqjune

Reputation: 552

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

Upvotes: 1

gasche
gasche

Reputation: 31459

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.

Upvotes: 10

Related Questions