User-generated exceptions

You can generate your own error using the RAISE EXCEPTION statement, as the following figure shows.
Figure 1: The RAISE EXCEPTION statement.
BEGIN
  ON EXCEPTION SET esql, eisam   -- trap all errors
    IF esql = -206 THEN          -- table not found
      -- recover somehow
    ELSE
      RAISE exception esql, eisam;  -- pass the error up
    END IF
  END EXCEPTION
    -- do something
END

In the example, the ON EXCEPTION statement uses two variables, esql and eisam, to hold the error numbers that the database server returns. The IF clause executes if an error occurs and if the SQL error number is -206. If any other SQL error is caught, it is passed out of this BEGINEND block to the last BEGINEND block of the previous example.