Consultor Eletrônico



Kbase P16358: The RETURN Statement never raises an error by itself
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   10/03/2003
Status: Unverified

SYMPTOM(s):

Evaluation of return-value for RETURN Statement fails as expected

No Error condition is raised

ERROR-STATUS:ERROR remains FALSE

Problem to achieve error handling with RETURN Statement

CAUSE:

Expected behavior.  The RETURN Statement never raises an error by itself.
The RETURN Statement itself has no NO-ERROR option for a failure that would happen during the evaluation of return-value.

It would be a bad idea to implement a NO-ERROR option for the RETURN Statement such as:
RETURN ERROR return-value NO-ERROR.
The fact that the syntax is ugly is nothing compared to the following brain-teaser:
How could we then rely on the ERROR-STATUS:ERROR anymore? Indeed, would it be coming from the RETURN ERROR, or the NO-ERROR because the evaluation of a value to return failed?

FIX:

Use a temporary Variable to work out the Value to Return with error handling, as illustrated bellow:DEFINE VARIABLE cReturnValue AS CHARACTER NO-UNDO.

cReturnValue = <something that may fail> NO-ERROR.
IF ERROR-STATUS:ERROR THEN RETURN ERROR "problem to work out Return Value".
RETURN cReturnValue.