Availability:built-in
[ISO]catch(:Goal,
+Catcher, :Recover)Behaves as call/1
if no exception is raised when executing Goal. If an
exception is raised using throw/1
while Goal executes, and the Goal is the innermost
goal for which Catcher unifies with the argument of throw/1,
all choice points generated by Goal are cut, the system
backtracks to the start of catch/3
while preserving the thrown exception term, and Recover is
called as in call/1.
The overhead of calling a goal through catch/3
is comparable to
call/1.
Recovery from an exception is much slower, especially if the exception
term is large due to the copying thereof or is decorated with a stack
trace using, e.g., the library library(prolog_stack)
based
on the
prolog_exception_hook/4
hook predicate to rewrite exceptions.