
error.pl -- 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.
type_error(+Type, +Term)
- Tell the user that Term is not of the expected Type. This error
is closely related to domain_error/2 because the notion of types
is not really set in stone in Prolog. We introduce the
difference using a simple example.
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, e.g.,
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 notpoint(_,_)
a type_error.
Undocumented predicates
The following predicates are exported, but not or incorrectly documented.