Error processing for UDFs
When an error occurs in processing a user-defined function (UDF), the system follows a specified model to handle the error.
Table function error processing
The error processing model for table function calls is as follows:
- If FIRST call fails, no further calls are made.
- If FIRST call succeeds, the nested OPEN, FETCH, and CLOSE calls are made, and the FINAL call is always made.
- If OPEN call fails, no FETCH or CLOSE call is made.
- If OPEN call succeeds, then FETCH and CLOSE calls are made.
- If a FETCH call fails, no further FETCH calls are made, but the CLOSE call is made.
This model describes the ordinary error processing for table UDFs. In the event of a system failure or communication problem, a call indicated by the error processing model may not be made.
Scalar function error processing
The error processing model for scalar UDFs, which are defined with the FINAL CALL specification, is as follows:
- If FIRST call fails, no further calls are made.
- If FIRST call succeeds, then further NORMAL calls are made as warranted by the processing of the statement, and a FINAL call is always made.
- If NORMAL call fails, no further NORMAL calls are made, but the FINAL call is made (if you have specified FINAL CALL). This means that if an error is returned on a FIRST call, the UDF must clean up before returning, because no FINAL call will be made.
This model describes the ordinary error processing for scalar UDFs. In the event of a system failure or communication problem, a call indicated by the error processing model may not be made.
Parent topic:
Writing UDFs as external functions