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


Exception handling

Version: 1.5#118 (2000/4/19, 18:13:43 CEST)

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 2: * 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 2:

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.

Usage 1: * ISO *

Usage 2: * ISO *

PREDICATE: halt/0:

halt

Halt the system, exiting to the invoking shell.

PREDICATE: halt/1:

halt(Code)

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

Usage 2: * ISO *

PREDICATE: abort/0:

abort

Abort the current execution.


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