Section "signal"

Situations might demand that a secondary coroutine controls a primary coroutine. The programming interface allows raising a soft signal in a primary coroutine from a secondary coroutine. The effect on the primary coroutine will be that the signal message is thrown as an error the first possible moment a call port is reached.

error(<signal message>,_)
The soft signal can be also programmatically raised from within the Prolog system, by using the predicate task_abort/2 on a given task. Tasks have an object reference as identity. Except for primordial task which is identified by the atom “main”. The task identity of the currently running task can be retrieved by the predicate task_self/1.

The following signal predicates are provided:
catch(G, E, F): [ISO 7.8.9]
The built-in succeeds whenever G succeeds. If there was a non-urgent exception that unifies with E, the built-in further succeeds whenever F succeeds.
throw(E): [ISO 7.8.9]
The predicate possibly fills the stack trace and then raises the exception B.
call_cleanup(G, C): [N208 8.15.5]
The predicate succeeds whenever G succeeds. The goal C is called for the exit, fail and error port of G, and continuation events.
setup_call_cleanup(S, G, C): [N215]
The predicate succeeds whenever G succeeds. The goal S is called for the call port of G. The goal C is called for the exit, fail and error port of G, and continuation events.
setup_undo(S, U):
The predicate succeeds whenever S succeeds. The predicate U is called for the first redo port of a goal before or equal to S.
shield(G):
The predicate succeeds whenever the goal G succeeds. The goal is executed without auto-yield.
unshield(G):
The predicate succeeds whenever the goal G succeeds. The goal is executed with auto-yield.
task_self(T):
The predicate succeeds in T with the task self.
task_abort(T, M):
The predicate succeeds. As a side effect the task T gets the message M signaled.