PublicShow -- 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.

- Jan Wielemaker
- Richard O'Keefe
- Ulrich Neumerkel
See also
- library(debug) and library(prolog_stack).
- print_message/2 is used to print (uncaught) error terms.
Source type_error(+ValidType, +Culprit)
Tell the user that Culprit is not of the expected ValidType. 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 point(_,_) a type_error.

Undocumented predicates

The following predicates are exported, but not or incorrectly documented.

Source uninstantiation_error(Arg1)
Source resource_error(Arg1)
Source permission_error(Arg1, Arg2, Arg3)
Source must_be(Arg1, Arg2)
Source is_of_type(Arg1, Arg2)
Source instantiation_error(Arg1)
Source representation_error(Arg1)
Source current_type(Arg1, Arg2, Arg3)
Source existence_error(Arg1, Arg2, Arg3)
Source existence_error(Arg1, Arg2)
Source domain_error(Arg1, Arg2)
Source syntax_error(Arg1)