title: HOWTO catch timeout exception in Prolog
body: <p>I want to limit "executing" of algorithm in prolog. Can you give me a hint, how to do it? I have found this predicate: <a href="http://www.swi-prolog.org/pldoc/doc_for?object=call_with_time_limit/2" rel="nofollow">call_with_time_limit</a> How can I catch the time_limit_exceeded exception? Thanks</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>I am trying it this way:</p>
  
  <pre><code>timeout(t) :-
      catch(call_with_time_limit(t, sleep(5)), X, error_process(X)).
  
  error_process(time_limit_exceeded) :- write('Timeout exceeded'), nl, halt.
  error_process(X) :- write('Unknown Error' : X), nl, halt.
  </code></pre>
  
  <p>but noting happend when I call timeout(1):</p>
  
  <pre><code>prolog :-
  timeout(1), 
  </code></pre>
  
  <p>but when I do it this way:</p>
  
  <pre><code>runStart :- call_with_time_limit(1, sleep(5)).
  
  timeout(1) :-
      catch(runStart, X, error_process(X)).
  
  error_process(time_limit_exceeded) :- write('Timeout exceeded'), nl, halt.
  error_process(X) :- write('Unknown Error' : X), nl, halt.
  </code></pre>
  
  <p>and again call timeout(1) everything is fine.
  Why? Thanks
  <strong>UPDATE 2:</strong></p>
  
  <p>Problem solved, it is necessary to have predcate "argument" with upper case...</p>