Header Name Exception Handling

Prev Next

Exception on headers not found

Normally, exceptions will be asserted column header names specified are not existing, e.g. [ cities : Best Restaurant, .. ]. However, the function table configure() allows differnt options such as

  • Referring to the 1st column (column 0) to return some default value
  • Referring to the last column to return some default value
  • Create a new column with header name Useful for write access. E.g. [ cities: City, Boston, Best Restaurant ] = Legal Seafood; would add a new row.



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

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

       table configure( table, column not found, first column );
       echo( [ table : City, Boston, Nation ] );

       table configure( table, column not found, last column );
       echo( [ table : City, Boston, Nation ] ); // Walking

       table configure( table, column not found, new column );
       [ table : City, Boston, Best Restaurant ] = Legal Seafood;
       [ table : City, Los Angeles, Best Restaurant ] = Jack in the Box; // A chain ...
       [ table : City, Zürich, Pizza Takeaway ] = Dieci; // A chain ...

       table list( table  );
USA
Walking
    0 : Country | City          | Famous attraction  | Moving along  | Best Restaurant | Pizza Takeaway
    1 : USA     | New York City | St. of Liberty     | Taxi          |                 |               
    2 : USA     | Washington    | Lincoln Statue     | The Beast     |                 |               
    3 : USA     | Philadelphia  | Independence hall  | PCC streetcar |                 |               
    4 : USA     | Boston        | Freedom trail      | Walking       | Legal Seafood   |               
    5 : USA     | San Francisco | Golden Gate        | Cable car     |                 |               
    6 : CAN     | Montréal      | Hôtel du Parlement | Skidoo        |                 |               
    7 : DAN     | Copenhagen    | Little Mermaid     | Bicycle       |                 |               
    8 : ITA     | Venice        | Doge's Palace      | Gondola       |                 |               
    9 : USA     | Los Angeles   | Hollywood          | Car           | Jack in the Box |               
   10 : AUT     | Vienna        | Prater             | Fiacre        |                 |               
   11 : THA     | Bangkok       | Wat Phra Kaeo      | Longtail boat |                 |               
   12 : SWI     | Zürich        | Street Parade      | Tram          |                 | Dieci         
   13 : FRA     | Paris         | Eiffel Tower       | Métro         |                 |               
   14 : SWI     | Davos         | Weissfluhgipfel    | Ski lift      |                 |               

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