6. Working with Transactions and Handling Errors : Error Handling : Error Handling in Embedded Applications : How to Define an Error-Handling Function
 
Share this page                  
How to Define an Error-Handling Function
You can define an error-handling function to be called when SQL errors occur.
To define an error-handling function, follow these steps:
1. Write the error-handling routine and link it into your embedded SQL application.
2. In the application, issue the following SET statement:
exec sql set_sql(errorhandler = error_routine);
where
error_routine is the name of the error-handling routine that was created. Do not declare error_routine in an SQL declare section, and do not precede error_routine with a colon; the error_routine argument must be a function pointer.
All SQL errors are trapped to your routine until error trapping is disabled (or until the application terminates). Forms errors are not trapped.
To disable the trapping of errors to your routine, your application must issue the following SET statement:
exec sql set_sql(errorhandler = 0 | error_var)
where error_var is a host integer variable having a value of 0.
Your error-handling routine must not issue any database statements in the same session in which the error occurred. If it is necessary to issue database statements in an error handler, open or switch to another session.
To obtain error information, your error-handling routine must issue the INQUIRE_SQL statement.