catch(?term, ?term)

This built-in predicate can catch (certain) exceptions generated by throw/1 or other built-in predicates, its prototype is:

   catch(Catcher, RecoverGoal).

The first argument is the term that is matched with an exception term, if the match is successful then the proving of RecoverGoal is started. If the match fails then throwing the exception continues. Exceptions generated during the proving of the RecoverGoal cannot be catched by the pattern of the same catch/2 clause.

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

Examples
catch(Y, do_catched_exception(Y)). catches all exceptions that match with the empty variable Y, i.e. all exceptions thrown are catched. The exception is passed on as an argument to the clause 'do_catched_exception'
catch(badcommand(X), (recover(X), do2(A))) only exceptions that match with 'badcommand(X)' are catched, if an exception is catched the expression (recover(X), do2(A)) becomes the new goal 

 

Exceptions
- -

 

 

info@trinc-prolog.com