Go to the first, previous, next, last section, table of contents.


Exception handling

Author(s): The CLIP Group.

Version: 1.11#222 (2004/5/24, 13:8:7 CEST)

Version of last change: 1.11#214 (2004/3/26, 19:41:58 CET)

This module includes predicates related to exceptions, which alter the normal flow of Prolog.

Usage and interface (exceptions)

Documentation on exports (exceptions)

PREDICATE: catch/3:

catch(Goal, Error, Handler)

Executes Goal. If an exception is raised during its execution, Error is unified with the exception, and if the unification succeeds, the entire execution derived from Goal is aborted, and Handler is executed. The execution resumes with the continuation of the catch/3 call. For example, given the code

p(X) :- throw(error), display('---').
p(X) :- display(X).

the execution of "catch(p(0), E, display(E)), display(.), fail." results in the output "error.".

Meta-predicate with arguments: catch(goal,?,goal).

Usage: * ISO *

PREDICATE: intercept/3:

intercept(Goal, Error, Handler)

Executes Goal. If an exception is raised during its execution, Error is unified with the exception, and if the unification succeeds, Handler is executed and then the execution resumes after the predicate which produced the exception. Note the difference with builtin catch/3, given the same code defined there, the execution of "intercept(p(0), E, display(E)), display(.), fail." results in the output "error---.0.".

Meta-predicate with arguments: intercept(goal,?,goal).

Usage:

PREDICATE: throw/1:

throw(Ball)

Raises an error, throwing the exception Ball, to be caught by an ancestor catch/3 or intercept/3. The closest matching ancestor is chosen. Exceptions are also thrown by other builtins in case of error.

PREDICATE: halt/0:

halt(halt

Halt the system, exiting to the invoking shell.

Usage: * ISO *

PREDICATE: halt/1:

halt(Code)

Halt the system, exiting to the invoking shell, returning exit code Code.

Usage: * ISO *

PREDICATE: abort/0:

abort(abort

Abort the current execution.


Go to the first, previous, next, last section, table of contents.