Executes the procedure call Goal. When Goal succeeds determinately, is cut, fails, or raises an exception, Cleanup is executed.
This construction can be used to ensure that Cleanup is executed as soon as Goal has completed execution, no matter how it finishes. In more detail:
call_cleanup/2 with a continuation C is called or
backtracked into, first Goal is called or backtracked
into. Then there are four possibilities:
call_cleanup/2Goal is raised, Cleanup is executed with continuation
In a typical use of
call_cleanup/2, Cleanup succeeds
determinately after performing some side-effect; otherwise,
unexpected behavior may result.
Note that the Prolog top-level operates as a read-execute-fail loop,
which backtracks into or cuts the query when the user
types ; or <RET> respectively. Also, some predicates, such as
are implemented in terms of
exceptions. All of these circumstances can trigger the execution of
Depends on the arguments.
Call errors (see ref-sem-exc).