set_error

Use the set_error v4 API method to communicate an error back to the server and eventually to the user.

Declaration

 void set_error(
		a_v4_extfn_proc_context *          cntxt,
		a_sql_uint32                       error_number,
		const char                         *error_desc_string
		)

Usage

Call the set_error API, if a UDF entry point encounters an error that should send an error message to the user and shut down the current statement. When called, set_error API rolls back the current statement and the user sees “Error raised by user-defined function: <error_desc_string>”. The SQLCODE is the negated form of the supplied <error_number>.

To avoid collisions with existing error codes, UDFs should generate error numbers between 17000 and 99999. If a number outside this range is provided, the statement is still rolled back, but the error message is "Invalid error raised by user-defined function: (<error_number>) <error_desc_string>" with a SQLCODE of -1577. The maximum length of error_desc_string is 140 characters.

After a call to set_error is made, the UDF entry point should immediately perform a return; eventually the _finish_extfn function is called to perform necessary cleanup. Do not subsequently call any other UDF entry points.

Parameters

Parameter Description
cntxt The procedure context object
error_number The error number to set
error_desc_string The message string to use
Related concepts
Scalar and Aggregate UDF Callback Functions