login

Availability:built-in
[ISO]throw(+Exception)
Raise an exception. The system looks for the innermost catch/3 ancestor for which Exception unifies with the Catcher argument of the catch/3 call. See catch/3 for details.

ISO demands that throw/1 make a copy of Exception, walk up the stack to a catch/3 call, backtrack and try to unify the copy of Exception with Catcher. SWI-Prolog delays making a copy of Exception and backtracking until it actually finds a matching catch/3 goal. The advantage is that we can start the debugger at the first possible location while preserving the entire exception context if there is no matching catch/3 goal. This approach can lead to different behaviour if Goal and Catcher of catch/3 call shared variables. We assume this to be highly unlikely and could not think of a scenario where this is useful.47I'd like to acknowledge Bart Demoen for his clarifications on these matters.

If an exception is raised in a call-back from C (see chapter 9) and not caught in the same call-back, PL_next_solution() fails and the exception context can be retrieved using PL_exception().