In order to run a group of queries in a simple query, I have tagged these queries and use forall/2
to call them:
query_all :-
forall(query(Q), (Q ->
format('yes: ~w~n',[Q]) ;
format('no : ~w~n',[Q]))).
so if I define something like query(true).
, I'll be able to see yes: true
from the output.
The problem here is that query( ... )
do not always exist, when prolog can't find anything that tagged query
, forall/2
will fail and cause exception saying "error(existence_error(procedure,query/1),forall/2)"
I want to handle this exception, but not to break the whole control flow.
I know catch/3 would help me but I don't know how to use it, my code is:
catch(query_all, error(existence_error(procedure,_),_), recovery).
recovery :-
format('error occurred.~n',[]).
but prolog says "native code procedure catch/3 cannot be redefined". Is there something I've missed?