Try OpenEdge Now
skip to main content
Error Handling
STOP and QUIT Condition Handling : STOP condition handling : Overriding default handling
 

Overriding default handling

The default handling for the STOP condition is almost always appropriate. However, you can override the default handling by adding the ON STOP phrase to a REPEAT, FOR, or DO statement. The example below demonstrates the ON STOP phrase:
DO ON STOP UNDO, RETRY:
IF RETRY THEN DO:
DISPLAY "Application encountered a STOP condition and will terminate.".
UNDO, LEAVE.
END.
ELSE RUN MissingCode.p.END.

DISPLAY "Application continues...". /* Never executes. */
In this example, the ON STOP phrase uses the RETRY branching option to provide an opportunity to recover from the STOP condition. The RETRY function in the IF statement allows you to determine if you are in RETRY mode.
This example uses the RETRY =TRUE branch of the IF statement to display another error message. This safe structure might be used to allow an application user to help locate a missing file or to ask the application user about whether or not to save data before terminating.
Here is the complete syntax for the ON STOP phrase:

Syntax

ON STOP UNDO
[label1]
[ , LEAVE [label2]
| , NEXT [label2]
| , RETRY [label1]
     | , RETURN [return-value |
                  ERROR [return-value |error-object-expression]| 
                 NO-APPLY ]
]
label1
The name of the block whose processing you want to undo. If you do not name a block with label1, ON STOP UNDO undoes the processing of the block started by the statement that contains the ON STOP phrase.
LEAVE [label2]
Indicates that after undoing the processing of a block, the AVM leaves the block labeled label2. If you do not name a block, the AVM leaves the block labeled with label1.
NEXT [label2]
Indicates that after undoing the processing of a block, the AVM executes the next iteration of the block you name with the label2 option. If you do not name a block with the NEXT option, the AVM executes the next iteration of the block labeled with label1.
RETRY [label1]
Indicates that after undoing the processing of a block, the AVM repeats the same iteration of the block you name with the label1 option.
RETRY is the default processing if you do not use LEAVE, NEXT, RETRY, or RETURN.
RETURN ...
Returns to the calling routine, or if there is no calling routine, returns to the OpenEdge Editor. The following table describes various RETURN cases:
Table 6. RETURN cases
Option
Description
return-value
The CHARACTER string you provide is passed to the caller. The caller can use the RETURN-VALUE function to read the returned value. For user-defined functions, the value must match the specified return type.
ERROR
Raises ERROR in the caller and undoes the current subtransaction. You cannot specify ERROR within a user-interface trigger block or a destructor.
ERROR return-value
Raises ERROR in the caller and undoes the current subtransaction (except for user-defined functions). The CHARACTER string you provide is available to the caller in the RETURN-VALUE function. In structured error handling, the AVM also creates an AppError object and stores the return-value in the ReturnValue property.
ERROR error-object-expression
In structured error handling, raises ERROR in the caller and undoes the current subtransaction.The specified error object is your code. If it is an AppError object, the caller can also use the RETURN-VALUE function to read the setting of the ReturnValue property.
NO-APPLY
In a user-interface trigger, prevents the AVM from performing the default behavior for that event.