1

Debugging an OCaml program that has an unhandled exception is fairly easy, because the program stops running and you can obtain a backtrace by running in ocamldebug or setting the OCAMLRUNPARAM environment variable to b. Is there any way to obtain such a backtrace for a handled exception?

Note: Modifying the program so it does not handle the exception is of course one option. However, I'd like to avoid modifying the program if possible. Something analogous to gdb's catch command would be great.

4

1 回答 1

2

有一个函数Printexc.print_backtrace将打印一个回溯,显示从引发异常的点到正在处理异常的当前点的堆栈。这可能会有所帮助,但请注意它不会打印完整的堆栈回溯。

我曾经写过一些 hacky 代码,使用Unix.fork它在类 Unix 系统上打印完整的堆栈回溯。请参阅我对打印堆栈跟踪的回答。(我不建议在生产中使用此代码。)

于 2013-02-25T02:19:23.800 回答