Users can write a handler for the specific exception occurring when an
undefined predicate is called by defining clauses for the hook
user:unknown_predicate_handler/3. This can be thought of as
a “global” exception handler for this particular exception, because
catch/3, its effect is not limited to a particular
goal. Furthermore, the exception is handled at the point where the
undefined predicate is called.
The handler can be written to apply to all unknown predicates, or to a class of them. The reference page contains an example of constraining the handler to certain predicates.
) is the trapped call to the undefined
predicate, then the hook is called as:
If this succeeds, then Prolog replaces the call to the undefined
predicate with the call to Module:NewGoal. Otherwise, the action
taken is governed by the
unknown Prolog flag
(see ref-lps-flg), the allowed values of which are:
Finally, this flag can be accessed by the built-in predicate:
This unifies OldValue with the current value, sets the flag to NewValue, and prints a message about the new value. See mpg-ref-unknown_predicate_handler.