Example 1: Defining a error handler function

This first code example defines an error handler function called my_error_handler. After connecting to the database, a SELECT statements tries to fetch a row from a table that does not exist, and raises SQL error -217 when connected to Informix®:
MAIN
  WHENEVER ERROR CALL my_error_handler
  DATABASE stores 
  SELECT dummy FROM systables WHERE tabid=1
END MAIN

FUNCTION my_error_handler()
  DISPLAY "Error:", STATUS
  EXIT PROGRAM 1
END FUNCTION
Program output:
Error:      -217