|Did you know ...||Search Documentation:|
|The exception term|
The predicate throw/1 takes a single argument, the exception term:
The ISO Standard stipulates that the exception term Exception
be of the form
User predicates are free to choose the structure of their exception
terms (i.e., they can define their own conventions) but should
adhere to the ISO Standard if possible, in particular for libraries.
Notably, exceptions of the shape
recognised by the development tools and therefore expressing unexpected
situations using these exceptions improve the debugging experience.
In SWI-Prolog, the Context argument is generally of the
context(Location, Message), where Location
describes the execution context in which the exception occurred, and Message
provides an additional description of the error. Any part of this
structure may be a fresh variable if no appropriate information exists.
While the Location argument may be specified as a
predicate indicator (Name/Arity), it is typically
filled by the
library(prolog_stack) library. This library recognised
uncaught errors or errors caught by catch_with_backtrace/3
and fills the Location argument with a backtrace.
ISO Standard exceptions are generally thrown via the predicates
library(error). Those predicates look exactly
like the ISO Standard error terms.