next up previous contents index
Next: Debugging and exceptions Up: Built-in predicates Previous: Meta-Call Predicates   Contents   Index


ISO compliant Exception handling

SWI-Prolog defines the predicates catch3 and throw1 for ISO compliant raising and catching of exceptions. In the current implementation (2.9.0), only part of the built-in predicates generate exceptions. In general, exceptions are implemented for I/O and arithmetic.

catch3:Goal, +Catcher, :Recover Behaves as call1 if no exception is raised when executing Goal. If a exception is raised using throw1 while Goal executes, and the Goal is the innermost goal for which Catcher unifies with the argument of throw1, all choicepoints generated by Goal are cut, and Recover is called as in call1.

The overhead of calling a goal through catch3 is very comparable to call1. Recovery from an exception has a similar overhead. throw1+Exception Raise an exception. The system will look for the innermost catch3 ancestor for which Exception unifies with the Catcher argument of the catch3 call. See catch3 for details.

If there is no catch3 willing to catch the error in the current Prolog context, the toplevel (prolog0) catches the error and prints a warning message. If an exception was raised in a callback from C (see foreign), PL_next_solution will fail and the exception context can be retrieved using PL_exception.



Subsections
next up previous contents index
Next: Debugging and exceptions Up: Built-in predicates Previous: Meta-Call Predicates   Contents   Index
Dr. Richard Botting 2001-12-12