Lookup Access Exception Handling

Prev Next

Exception on rows not found

Normally, exceptions will be asserted when a table reference with lookup access fails, e.g. [ cities : City, Tokyo ] would assert an error message and stops program execution. However, the function table configure() allows differnt options such as

  • Referring to the header row and returning the header name
  • Referring to the 1st row (below the header row) to return some default value
  • Referring to the last row (below the header row) to return some default value
  • Create a new row. Useful for write access. E.g. [ cities: City, Toyko, Moving along ] would add a new row.


  table load( table, "Examples\Cities.csv" );

  table keep columns( table, { City, Famous attraction, Moving along} );

  table configure( table, row not found, header row );
  echo( [ table : City, Boston   , Moving along]  ); // 'Walking'
  echo( [ table : City, New Haven, Moving along]  ); // 'Moving along' (Header row)
  echo;

  table configure( table, row not found, new row );
  [ table : City, Kiruna, Moving along ] = Cross Country Skis; // Adds new row

  table list( table, 1st row, -3 ); // List last 3 rows
Walking
Moving along

    0 : City   | Famous attraction | Moving along      
   13 : Paris  | Eiffel Tower      | Métro             
   14 : Davos  | Weissfluhgipfel   | Ski lift          
   15 : Kiruna |                   | Cross Country Skis

Try it yourself: Open LAN_Features_lookup_access_exception_handling.b4p in B4P_Examples.zip. Decompress before use.