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