Home Contents Index Summary Previous Next

A.3 Exception Handling

A start has been made to make exception handling available to the Prolog user. On exceptions a dynamic and multifile defined predicate exception/3 is called. If this user defined predicate succeeds Prolog assumes the exception has been taken care of. Otherwise the system default exception handler is called.

exception(+Exception, +Context, -Action)
Dynamic predicate, normally not defined. Called by the Prolog system on run-time exceptions. Currently exception/3 is only used for trapping undefined predicates. Future versions might handle signal handling, floating exceptions and other runtime errors via this mechanism. The values for Exception are described below.

undefined_predicate
If Exception is undefined_predicate Context is instantiated to a term Name/Arity. Name refers to the name and Arity to the arity of the undefined predicate. If the definition module of the predicate is not user, Context will be of the form <Module>:<Name>/<Arity>. If the predicate fails Prolog will print the default error warning and start the tracer. If the predicate succeeds it should instantiate the last argument either to the atom fail to tell Prolog to fail the predicate or the atom retry to tell Prolog to retry the predicate. This only makes sense if the exception handler has defined the predicate. Otherwise it will lead to a loop.

warning
If prolog wants to give a warning while reading a file, it will first raise the exception warning. The context argument is a term of the form warning(<Path>, <LineNo>, <Message>), where Path is the absolute filename of the file prolog is reading; LineNo is an estimate of the line number where the error occurred and Message is a Prolog string indicating the message. The Action argument is ignored. The error is supposed to be presented to the user if the exception handler succeeds. Otherwise the standard Prolog warning message is printed.

This exception is used by the library(emacs_interface), that integrates error handling with GNU~Emacs.