5.11 Catching Exceptions

Usually, exceptions that occur during debugging sessions are displayed only in trace mode and for invocation boxes for predicates with spypoints on them, and not during skips. However, it is sometimes useful to make exceptions trap to the debugger at the earliest opportunity instead. The hook predicate user:error_exception/1 provides such a possibility:

error_exception(+Exception) hook
user:error_exception(+Exception)
This predicate is called at all Exception ports. If it succeeds, the debugger enters trace mode and prints an exception port message. Otherwise, the debugger mode is unchanged and a message is printed only in trace mode or if a spypoint is reached, and not during skips.

Note that this hook takes effect when the debugger arrives at an Exception port. For this to happen, procedure boxes have to be built, e.g. by running (the relevant parts of) the program in debug mode.

A useful definition that ensures that all standard error exceptions causes the debugger to enter trace mode, is as follows:

     :- multifile user:error_exception/1.
     user:error_exception(error(_,_)).

(this example would not have worked prior to SICStus Prolog 4.0.5).


Send feedback on this subject.