|Did you know ...||Search Documentation:|
|library(error): Error generating support|
This module provides predicates to simplify error generation and checking. It's implementation is based on a discussion on the SWI-Prolog mailinglist on best practices in error handling. The utility predicate must_be/2 provides simple run-time type validation. The *_error predicates are simple wrappers around throw/1 to simplify throwing the most common ISO error terms.
Suppose an argument must be a non-negative integer. If the actual argument is not an integer, this is a type_error. If it is a negative integer, it is a domain_error.
Typical borderline cases are predicates accepting a compound term,
point(X,Y). One could argue that the basic type is a
compound-term and any other compound term is a domain error. Most Prolog
programmers consider each compound as a type and would consider a
compoint that is not
point(_,_) a type_error.
|Term||is the term that needs (further) instantiation. Unfortunately, the ISO error does not allow for passing this term along with the error, but we pass it to this predicate for documentation purposes and to allow for future enhancement.|
open(File, read, input)cannot succeed because the system will allocate a new unique stream handle that will never unify with
1ais not a valid number.
Most of these types are defined by an arity-1 built-in predicate of the same name. Below is a brief definition of the other types.
boolean one of
char Atom of length 1 code Representation Unicode code point chars Proper list of 1-character atoms codes Proper list of Unicode character codes text One of
Number [FloatL..FloatU] nonneg Integer
positive_integer Integer > 0 negative_integer Integer < 0
Ground term that is member of L encoding Valid name for a character encoding cyclic Cyclic term (rational tree) acyclic Acyclic term (tree)
Proper list with elements of Type list_or_partial_list A list or an open list (ending in a variable
Note: The Windows version can only represent Unicode code points up
^16-1. Higher values cause a representation error on
most text handling predicates.
type_error(Type, Term)if Term is not of Type.