Leaves the local or remote procedure, user-defined function, ON trigger, method of a class, class constructor or destructor, or property accessor, and returns to the caller. If there is no caller, returns to the Procedure Editor or Progress Developer Studio for OpenEdge tool.
For more information on remote procedures, see OpenEdge Application Server: Developing AppServer Applications.
This has different behavior depending on whether a value can be returned from the current context. From contexts that don’t return a value, this is used to set RETURN-VALUE.
For a procedure or ON trigger block, the value is used to set RETURN-VALUE:
For a VOID method, you cannot set a return-value.
You cannot use the ERROR option in a user-interface trigger block to raise ERROR outside of the trigger block.
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 (?). See OpenEdge Development: ABL Error Handling for more information.
To retrieve the return value in the caller, catch the Progress.Lang.AppError using a CATCH statement and obtain the ReturnValue property of the AppError. Alternatively, the caller can access the RETURN-VALUE function.
If you do not specify either error-return-value or error-object-expression, both the RETURN-VALUE function as well as the AppError ReturnValue property is set to the empty string("").
An expression that resolves to a specific error object. It must be an object derived from Progress.Lang.ProError or an object of a class that implements Progress.Lang.Error. The compiler generates an error if these rules are not met. Note that the only error object you can instantiate directly is a Progress.Lang.AppError object or a subclass.
RETURN ERROR error-object-expression immediately returns to the caller before throwing the error object.
The following code demonstrates using RETURN in a user-defined function.
DEFINE VARIABLE dTemp AS DECIMAL NO-UNDO INITIAL 0. FUNCTION CtoF RETURNS DECIMAL (INPUT dCelsius AS DECIMAL): RETURN (dCelsius * 1.8) + 32. END. MESSAGE dTemp "degrees Celsius is" CtoF(dTemp) "degrees Fahrenheit." SKIP VIEW-AS ALERT-BOX. |
Output:
0 degrees Celsius is 32 degrees Fahrenheit. |
The following code illustrates using RETURN ERROR in a user-defined function.
DEFINE VARIABLE iFuncReturn AS INTEGER INITIAL 99 NO-UNDO. FUNCTION ErrorTest RETURNS INTEGER: RETURN ERROR. END FUNCTION. ASSIGN iFuncReturn = ErrorTest(). IF iFuncReturn EQ ? THEN MESSAGE "Error in user-defined function." view-as alert-box. |
Output:
Error in user-defined function. |
The following code demonstrates using RETURN ERROR with an error object.
DEF VAR ix AS INT. RUN proc NO-ERROR. IF ERROR-STATUS:ERROR THEN DO: DO ix = 1 TO ERROR-STATUS:NUM-MESSAGES: /* this will be 2 */ MESSAGE ERROR-STATUS:GET-MESSAGE(ix) ERROR-STATUS:GET-NUMBER(ix). END. END. PROCEDURE proc: DEFINE VAR err AS PROGRESS.Lang.AppError. err = NEW PROGRESS.Lang.AppError("The car cannot be rented",1). err:AddMessage ("No driver's license was provided", 98). RETURN ERROR err. END. |
Output:
The car cannot be rented 1 No driver's license was provided 98 |