Consultor Eletrônico



Kbase P10608: How to catch Progress errors (4GL)
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   8/4/2009
Status: Verified

GOAL:

How to catch Progress errors

GOAL:

Can errors be caught programmatically

GOAL:

How to write 4GL to monitor for errors

FACT(s) (Environment):

All Supported Operating Systems
Progress 7.x
Progress 8.x
Progress 9.x
OpenEdge 10.x

FIX:

Errors can be caught programmatically via different 4GL statements so that the application can handle what is done about the errors. Below are a few examples of different syntax that can be used to monitor or catch errors.
1) ON ERROR:
This syntax describes the processing that takes place when there is an error within a DO block, REPEAT Block, FOR EACH, etc.

DO i = 1 to 10 ON ERROR, UNDO RETRY:

This syntax specifies that when there is an an error the block is to be undone and to retry it. If using this syntax, the next example shows how to catch the error.

2) RETRY statement
In the example 1, the DO block was undone and the RETRY indicator was set to true. The application can then test to see if this is a RETRY and perform an action if it is.

IF RETRY THEN DO:
<write error handling action here>
END.

3) RETURN-VALUE
The RETURN statement can return a value to the calling procedure which can indicate if an error occurred. By examining the RETURN-VALUE, the application can then be coded to handle the error.
In the called program, if an error occurred, then the return value would be set and returned to the calling procedure.
In called procedure:
IF ERROR-STATUS:ERROR = TRUE THEN
RETURN "error".

In calling procedure:
IF RETURN-VALUE = "error" THEN DO:
<application handles error code>.
END.

4) ERROR-STATUS handle
The ERROR-STATUS handle has two attributes that a 4GL client can use to determine if an error has occurred: ERROR and NUM-MESSAGES. The syntax to use is:

IF ERROR-STATUS:ERROR AND ERROR-STATUS:NUM-MESSAGES > 0 THEN DO:
<application code to handle error>
END.