throw(+term) [ISO]

The throw predicate raises an exception that can be catched by patterns of the catch/3 clause. The single parameter of must be an instantiated variable or a term. Proving the throw/1 predicate involves searching for a catcher for the exception. The active prove tree is searched for a suitable and active catcher, if no catcher can be found an error message is generated and the execution of the program stops. The IDE of Trinc-Prolog freezes a Prolog program just before it exits if an exception is not handled, the values of variables can then be inspected.

An active catcher is a catch/2 or a catch/3 clause of which the goal (not the recovergoal) is being executed.

see also: always/2 call/1 catch/2 catch/3 fail/0 halt/0 halt/1 if-then/2 if-then-else/2 once/1 repeat/0 true/0

Examples
catch(throw(true), X, X). an exception with the value 'true' is thrown, it is immediately catched by the second argument of catch/3 and a recovergoal with the value of X, which is true, is started, this recovergoal succeeds
catch(throw(exit(1)), exit(X), write(X)). succeeds with substitution X=1 and '1' is written to the current output stream

 

Exceptions
Term is a variable an instantiation_error is thrown

 

 

info@trinc-prolog.com