Next: mpg-ref-call_residue_vars, Previous: mpg-ref-call, Up: mpg-bpr [Contents][Index]
call_cleanup/2
call_cleanup(+Goal, +Cleanup)
Executes the procedure call Goal. When Goal succeeds determinately, is cut, fails, or raises an exception, Cleanup is executed.
callable, must be nonvar
callable, must be nonvar
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:
When 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/2
Goal
is raised, then Cleanup is executed with continuation
raise_exception(E)
.
fail
.
raise_exception(E)
.
In the above, Goal is executed as if by call/1
,
whereas Cleanup is executed as if by once/1
.
In a typical use of call_cleanup/2
, Cleanup succeeds
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
halt/[0,1]
and abort/0
,
are implemented in terms of
exceptions. All of these circumstances can trigger the execution of
Cleanup.
Depends on the arguments.
Call errors (see ref-sem-exc).