You can throw exceptions from your own code using:
The argument to this predicate is the exception term, an arbitrary non-variable term. See mpg-ref-throw.
If the exception term contains attributed variables
(see lib-atts) or suspended goals (see ref-sem-sec),
those attributes don’t become part of the exception. To retain the
attributes, you can use
copy_term/3 (see ref-lte-cpt).