My program is generating this:


I don’t know which spot is causing this, or the call tree. I would like to start the tracer when an error occurs so I can examine where it’s at. trace_on_error does not seem to be a predicate though. For what it’s worth, there are more than one catch calls in this stack, so some suggestions are not viable, and setting debug=true for the duration is also not always viable, though sometimes it is.

Use the gui tracer and edit/exceptions or Prolog/Edit exceptions from the PceEmacs editor windows. That does run in debug mode. If you cannot afford that, it should produce a backtrace for uncaught exceptions. If the exception is caught you can use catch_with_backtrace/3 instead of catch/3 or you can extend the guard definition for library(prolog_stack) (GitHub). See the library.

1 Like

Edit Exceptions in the prolog editor. Who knew that existed and had error defined to trace “if not caught”?

catch_with_backtrace is also handy.

1 Like

Note that you should only use this if you want to print the exception. If you catch it do do something else you should be aware that getting the backtrace into the exception is pretty expensive, in particular if source code locations are enabled (default).