You can either declare query/1
as dynamic in your code adding this line:
:-dynamic(query/1).
or use catch/3
as you suggested, however you don't have to redefine it but use it instead, e.g:
query_all :-
catch(
forall(query(Q), (Q ->
format('yes: ~w~n',[Q]) ;
format('no : ~w~n',[Q]))),
error(existence_error(procedure, _), _), format('error occurred.~n', [])).