Exceptions raised by the Prolog system are called errors. The set of exception classes used by the system has been kept small. Here is a complete list:
The format of the exception raised by the built-in predicates is:
error(ISO_Error, SICStus_Error)
where ISO_Error is the error term prescribed by the ISO Prolog standard, while SICStus_Error is the part defined by the standard to be implementation dependent. In the case of SICStus Prolog, this is the SICStus error term, which normally contains additional information, such as the goal and the argument number causing the error. Arguments are numbered from 1 upwards.
The list below itemizes the error terms, showing the ISO_Error and SICStus_Error form of each one, in that order. Note that the SICStus and ISO error terms do not always belong to the same error class, and that the context and consistency error classes are extensions to the ISO Prolog standard.
The goal part of the error term may optionally have the form
$@(
Callable,
PC)
where PC is an internal
encoding of the line of code containing the culprit goal or one
of its ancestors. To decompose an annotated goal AGoal into a Goal proper
and a SourceInfo descriptor term, indicating the source
position of the goal, use:
?- goal_source_info(AGoal, Goal, SourceInfo).
The reference page gives details about the SourceInfo format.
instantiation_error
instantiation_error(
Goal,
ArgNo)
type_error(
TypeName,
Culprit)
type_error(
Goal,
ArgNo,
TypeName,
Culprit)
domain_error(
Domain,
Culprit)
domain_error(
Goal,
ArgNo,
Domain,
Culprit)
existence_error(
ObjectType,
Culprit)
existence_error(
Goal,
ArgNo,
ObjectType,
Culprit,
Reserved)
unknown
Prolog flag is set to error
, this
error is raised with ArgNo set to 0 when an undefined
predicate is called.
permission_error(
Operation,
ObjectType,
Culprit)
permission_error(
Goal,
Operation,
ObjectType,
Culprit,
Reserved)
context_error(
ContextType,
CommandType)
context_error(
Goal,
ContextType,
CommandType)
syntax_error(
Message)
syntax_error(
Goal,
Position,
Message,
Tokens,
AfterError)
read/[1,2]
or assembling a number from its characters with
number_chars/2
or number_codes/2
. In the former case this error is raised only if
the syntax_errors
flag is set to error
.
evaluation_error(
ErrorType,
Culprit)
evaluation_error(
Goal,
ArgNo,
ErrorType,
Culprit)
representation_error(
ErrorType)
representation_error(
Goal,
ArgNo,
ErrorType)
consistency_error(
Culprit1,
Culprit2,
Message)
consistency_error(
Goal,
Culprit1,
Culprit2,
Message)
resource_error(
ResourceType)
resource_error(
Goal,
ResourceType)
memory
.
system_error
system_error(
Message)
Most exception terms include a copy of the Goal that raised the exception.
In general, built-in predicates that cause side-effects, such as the opening of a stream or asserting a clause into the Prolog database, attempt to do all error checking before the side-effect is performed. Unless otherwise indicated in the documentation for a particular predicate or error class, it should be assumed that goals that raise exceptions have not performed any side-effect.