Trap/1 for trapping errors

I’ve pushed a patch, adding library(prolog_debug). This does:

  • Move spy/1 and related predicates from the core system to the library. There is no reason to put this stuff in the core system. With autoloading, most people won’t notice. If you disable autoloading you can load this library from your init.pl file.

  • added trap/1 and notrap/1. The argument is a term that unifies with the formal part of a error(Formal. ImplDependent) exception term. If an exception happens that unifies, the debugger is started. The graphical debugger library adds gtrap/1 to immediately get the graphical equivalent (as gtrace/0, gspy/1, etc.).

I’ve had the trap predicates in my personal library for a while and really like them. If there is an error, just run

?- gtrap(_), my_goal.

and the debugger stops close to where you need to search. I particularly like gtrap/1 in combination with the new =>/2 rules and det/1. It is an efficient way to debug unexpected failures and choice points you didn’t want to leave.

Naming and precise semantics are, as with all new functionality, subject to discussion and changes.

4 Likes

gtrap/1 seems not to be available directly from the top level (version version 8.3.28-23-gbe3ded1f9):

1 ?- gtrace.
% The graphical front-end will be used for subsequent tracing
true.

[trace] 2 ?- gtrap(_), throw(error(kol,kll)).
Correct to: "gui_tracer:gtrap(_)"? yes
[...]

Most likely the build is not really complete. There are still some problems in making incremental builds be really reliable :frowning: It is a good practice to run ninja twice after a pull … Works fine for me.

1 Like

This topic was created with the Announce category but as noted the Announce category should not have replies.

Note : Use of this category will not allow for replies to the announcement. The intent being that each person should start a separate topic as needed to avoid a cacophony of divergent replies.

Since some of the replies have been approved by an admin/moderator and are being replied to I am just changing the category to Resources which is for a similar use and does allow replies.

  • This topic is related to announce , but announce is more about announcing new releases. It is also related to help! , but help is more about how to do something and finding out why something doesn’t work as you expect.

You’re right, works after a ninja clean && ninja

Just running ninja twice is typically enough for problems like this. No need to clean.

Could you illustrate this use with a simple example …

thanks,

Dan