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:|
(term_t)0if the Prolog goal simply failed. If there is an exception, PL_exception() returns a term reference that contains the exception term.
PL_exception(0) returns the pending
exception in the current query or
(term_t)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.