The user-defined function, which is defined by the FUNCTION statement, returns a value of a specific data type as its primary function. The RETURN statement is the tool you use to specify in the function body what value to return to the caller. This fact makes it impossible to use the RETURN ERROR statement in the same way as it is used in other blocks.
RETURN ERROR in a user-defined function does not raise error in the caller. Instead, it sets the target variable of the function to the unknown value. Therefore, you could perform error checking on a function call by checking for the unknown value after a function call. This technique only works if the function uses the RETURN ERROR statement and the target variable has a value other than the unknown value at the time of the function call. For example:
DEFINE VARIABLE iFuncReturn AS INTEGER INITIAL 99 NO-UNDO.
FUNCTION ErrorTest RETURNS INTEGER:
RETURN ERROR.
END FUNCTION.
ASSIGN iFuncReturn = ErrorTest().
IF iFuncReturn EQ ? THEN
DISPLAY "Error in user-defined function.".