A.16 library(error): Error generating support
All Application Manual Name SummaryHelp

  • Documentation
    • Reference manual
      • The SWI-Prolog library
        • library(error): Error generating support
          • type_error/2
          • domain_error/2
          • existence_error/2
          • existence_error/3
          • permission_error/3
          • instantiation_error/1
          • uninstantiation_error/1
          • representation_error/1
          • syntax_error/1
          • resource_error/1
          • must_be/2
          • is_of_type/2
          • has_type/2
          • current_encoding/1
          • current_type/3
    • Packages
Availability::- use_module(library(error)).(can be autoloaded)
Sourcetype_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.