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 compound that is not
The following predicates are exported, but not or incorrectly documented.
- current_type(Arg1, Arg2, Arg3)
- permission_error(Arg1, Arg2, Arg3)
- must_be(Arg1, Arg2)
- is_of_type(Arg1, Arg2)
- existence_error(Arg1, Arg2)
- domain_error(Arg1, Arg2)
- existence_error(Arg1, Arg2, Arg3)