Next: , Previous: , Up: mpg-bpr   [Contents][Index]


11.3.34 catch/3   ISO

Synopsis

catch(+ProtectedGoal, -Exception, +Handler)

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

Arguments

:ProtectedGoal

callable, must be nonvar

Exception

term

:Handler

callable, must be nonvar

Examples

Fail on exception:

:- meta_predicate fail_on_exception(0).
fail_on_exception(C):-
    catch(C, E, print_exception_then_fail(C, E)).

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

Backtracking

Depends on ProtectedGoal and Handler.

Exceptions

None.

See Also

ref-ere.


Send feedback on this subject.