Undefined Predicates

There is a difference between predicates that have no definition and predicates that have no clauses. The latter case is meaningful e.g. for dynamic predicates (see Declarations) that clauses are being added to or removed from. There are good reasons for treating calls to undefined predicates as errors, as such calls easily arise from typing errors.

The system can optionally catch calls to predicates that have no definition. First the user defined predicate user:unknown_predicate_handler/3 (see Exception) is called. If undefined or if the call fails the action is governed by the state of the unknown Prolog flag, which can be:

trace
which causes calls to undefined predicates to be reported and the debugger to be entered at the earliest opportunity.
error
which causes calls to such predicates to raise an exception (the default state). See Exception.
warning
which causes calls to such predicates to display a warning message and then fail.
fail
which causes calls to such predicates to fail.

Calls to predicates that have no clauses are not caught.

The built-in predicate unknown(?OldState, ?NewState) unifies OldState with the current state and sets the state to NewState. The built-in predicate debugging/0 prints the value of this state along with its other information. This state is also controlled by the unknown Prolog flag.