Raising Exceptions

You can raise exceptions from your own code using the built-in predicate

     raise_exception(+ExceptionCode)
     

The argument to this predicate is the exception code; 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.

Error messages like the one shown above are printed using the built-in predicate print_message/2. One of the arguments to print_message is the exception code. print_message can be extended, as described in ref-msg, so that you can have appropriate error messages printed corresponding to your own exception classes.