You can raise exceptions from your own code using one of the two equivalent built-in predicates:
The argument to this predicate is the exception term; it is an arbitrary non-variable term of which the principal functor indicates the exception class. You can use the same exception classes as the system (see ref-ere-err), or you can use your own exception classes.
See lib-types for an alternative interface to raising error exceptions, which tries to include line number information for source-linked debugging.
Error messages like the one shown above are printed using the built-in
print_message/2. One of the arguments to
print_message/2 is the exception term.
can be extended, as described in ref-msg, so that you can have
appropriate error messages printed corresponding to your own exception
If the exception term contains attributed variables
(see lib-atts) or suspended goals (see ref-sem-sec),
those attributes do not become part of the exception. To retain the
attributes, you can use
copy_term/3 (see ref-lte-cpt).