Error processing for UDFs

When an error is encountered when processing a UDF, the system follows a specified model.

Table function error processing

The error processing model for table function calls is as follows:

  1. If FIRST call fails, no further calls are made.
  2. If FIRST call succeeds, the nested OPEN, FETCH, and CLOSE calls are made, and the FINAL call is always made.
  3. If OPEN call fails, no FETCH or CLOSE call is made.
  4. If OPEN call succeeds, then FETCH and CLOSE calls are made.
  5. If a FETCH call fails, no further FETCH calls are made, but the CLOSE call is made.
Note: 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:

  1. If FIRST call fails, no further calls are made.
  2. 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.
  3. 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.
Note: 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.