Product Documentation

FairCom Java & .NET Stored Procedures

Previous Topic

Next Topic

Throw Custom Error Message on Stored Procedure or UDF Exception

This modification provides the capability to return an error message from a stored procedure or user-defined function (UDF).

Before this modification, the only way for a stored procedure to set the return code to a value different than 0 was to throw a DhSQLException() either directly (only when using the NetBeans plugin to generate the stored procedure) by:

throw new DhSQLException(678,"my error message");

or through the DhSQLThrow class:

DhSQLThrow.throwSQLException(678,"my error message");

In both cases the error code returned was interpreted as a known SQL error code and the error message was set to the one for the specific error code returned, ignoring the message.

This modification adds a preferred way of returning an error message by calling the new fail(String message) method. This method causes the stored procedure to terminate with error -26015 and sets the error message to the string passed in. The message will be truncated if it is larger than 510 characters. For example:

ISQL> CREATE PROCEDURE excp()

BEGIN

fail("my error message");

END

ISQL> call excp();

ISQL> error(-26015): my error message

TOCIndex