Unobvious behavior: The returned term is cleared by PL_clear_exception so if you want to hang on to it, you'll need to copy it to a new term.
|Did you know ...||Search Documentation:|
PL_exception(0) returns the pending
exception in the current query or 0 if no exception is pending. This can
be used to check the error status after a failing call to, e.g., one of
the unification functions.