Next:
Directives and Prolog Flags
Up:
catch/3
Previous:
catch/3
Contents
Index
Examples:
q(X)
, which is defined in the following, is equivalent to
p(X)
, except all interruptions are ignored.
q(X):-catch(p(X),interrupt,q(X)).
The query
catch(p(X),undefined_predicate(_),fail)
fails
p(X)
if an undefined predicate is called during its execution.
The query
catch(q,C,write(hello_q))
, where
q
is defined in the following, succeeds with the unifier
C=c
and the message
hello_q
.
q :- r(c). r(X) :- throw(X).
The query
catch(p(X),E,p(X)==E)
for the following program fails, because
E
is unified with a renamed
copy
of
p(X)
, rather than
p(X)
itself.
p(X):-throw(p(X)).
Neng-Fa Zhou 2013-01-25