Basic VSP Programming tutorial
Error Recovery Error handling in VSPs

## Preliminaries

- When processing some form data in VSPs, there may be errors in the PL code (for example due to deadlock condition).

- The most popular way of catching the SQL errors is to declare an exception handler.

      declare error varchar;
      error := null;
      declare exit handler for sqlstate '*', not found result { error := __SQL_MESSAGE; };
       {
          -- some operation(s) that may cause a SQL error
       }
      if (error is not null)
        -- print the error message

- To simplify VSP production, the error handler can be written in a common file and included in each page.

- The external file can be included using the following markup:

      <?include path_to_the_external_file.extension ?>

## Deadlock Example

The first example demonstrates the creation of a universal deadlock handler. If this file is included in any VSP the deadlock condition will cause a retry up to 3 times on an operation that follows the handler. The VSP simulates the deadlock situation by signalling the error. The error handler is therefore called.

## Calculator with error handler

The second example is the vs_b_3 Calculator example. In this example there is an added handler to trap errors such as division by zero, and entering characters instead of numbers.