11.3.144 on_exception/3

Synopsis

on_exception(-Exception, +ProtectedGoal, +Handler)

Specify an exception handler for ProtectedGoal, and call ProtectedGoal, as described in ref-ere.

Arguments

Exception
term
:ProtectedGoal
callable, must be nonvar
:Handler
callable, must be nonvar

Exceptions

Call errors (see ref-sem-exc).

Examples

Fail on exception:

     :-meta_predicate fail_on_exception(0).
     fail_on_exception(C):-
         on_exception(E,C,print_exception_then_fail(C,E)).
     
     print_exception_then_fail(C,E):-
         format('Exception occured while calling ~q:~n', [C]),
         print_message(warning,E),
         fail.

Backtracking

Depends on ProtectedGoal and Handler.

See Also

ref-ere.


Send feedback on this subject.