Documentation Prolog Predicate Reference builtin catch/3

catch/3

Enable recovery from exceptions.

Description

catch( +callable_term, ?term, +callable_term )

catch(Goal, Catcher, Handler) behaves as call/1 if no exception is raised when executing Goal. If an exception is raised using throw/1 while Goal executes, and the Goal is the innermost goal for which Catcher unifies with the argument of throw/1, all choice points generated by Goal are cut, the system backtracks to the start of catch/3 while preserving the thrown exception term, and Handler is called as in call/1.

Implementation