title: Can I use EXCEPTIONs in a FOR LOOP to force continuation on error?
body: <p>Can I use EXCEPTIONs in FOR loops to force continuation when (predictable or not) errors occur? Here is a snippet:</p>
  
  <pre><code>FOR temp_rec IN tlcursor LOOP
    tl2 := temp_rec; --the location to be updated
    --Do the Routing and UPDATE the taxilocs row.
    UPDATE taxilocs20120113 
       SET route = pgr_trsp (
          'SELECT * FROM th_2po_4pgr',
          tl1.map_id, tl1.map_pos, tl2.map_id, tl2.map_pos, false, true);
    tl1 := tl2;
  END LOOP;
  </code></pre>
  
  <p>An example is, that during the first iteration, <code>tl1</code> is not assigned. Another could be that the function <code>pge_trsp()</code> provides no result. If any of this occurs during execution, can I force the loop to continue?<br>
  <strong>Update!!</strong><br>
  Here is my latest piece of code:  </p>
  
  <pre><code>CREATE OR REPLACE FUNCTION fm_seqrouting() RETURNS integer AS $$
  --Declarations
  DECLARE 
      tlcursor SCROLL CURSOR FOR SELECT 
          oid,
          veh_id,
          date_time AS dt,
          th_2po_4pgr_id AS map_id,
          th_2po_4pgr_position AS map_pos FROM testlocs
          ORDER BY veh_id, dt;
      tl1 RECORD;
      tl2 RECORD;
      i integer;
  BEGIN
  --CODE to calculate routes and update table
      i := 0;
      FOR temp_rec IN tlcursor LOOP
          tl2 := temp_rec; --the location to be updated
          BEGIN --Nest the UPDATE in a block to esace errors
          --Do the Routing and UPDATE the taxilocs row.
          UPDATE taxilocs20120113 
              SET "pgRoute" = pgr_trsp (
                  'SELECT * FROM th_2po_4pgr',
                  tl1.map_id, tl1.map_pos, tl2.map_id, tl2.map_pos, false, true)
          WHERE taxilocs20120113.oid = tl2.oid;
          i := i + 1;
          EXCEPTION
              WHEN SQLSTATE '55000' THEN NULL;
              WHEN SQLSTATE 'XX000' THEN NULL;
              WHEN SQLSTATE '38001' THEN NULL;
          END;
          tl1 := tl2;
      END LOOP;
  RETURN i;
  END;
  $$ LANGUAGE plpgsql;  
  </code></pre>
  
  <p>The truth is it is very straining memory-wise, but I am new to programming (I am not even a programmer). Any tips appreciated!</p>