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

Overriding default handling

The default handling of the QUIT condition is almost always appropriate. However, by using the ON QUIT phrase in a REPEAT, FOR EACH, or DO block you can modify the default QUIT condition handling.
This example uses the ON QUIT phrase to provide a branch within the block that can be executed before the application quits:
DO ON QUIT UNDO, RETRY:
IF RETRY THEN DO:
DISPLAY "Application encountered a QUIT condition and will terminate.".
UNDO, LEAVE.
END.

FIND FIRST customer WHERE CustNum = 1000 NO-ERROR.

IF ERROR-STATUS:ERROR THEN QUIT.
END.

DISPLAY "Application continues...". /* Never executes. */
The RETRY function checks whether the block is in RETRY mode and displays an error message. You can easily replace the DISPLAY statement that performs tasks necessary to ensure an orderly shutdown of the application.
Here is the complete syntax for the ON QUIT phrase:

Syntax

ON QUIT
[ UNDO [label1]]
[ , LEAVE [label2]
| , NEXT [label2]
| , RETRY [label1]
     | , RETURN [return-value |
                  ERROR [return-value |error-object-expression]|
                  NO-APPLY ]
]
UNDO [label1]
Indicates that the specified block is undone. If you do not specify the UNDO option, then the current transaction is committed when the QUIT statement is executed.
LEAVE [label2]
Indicates that after committing or undoing the transaction, the AVM leaves the block labeled label. If you do not name a block, the AVM leaves the block with the ON QUIT phrase in its heading.
NEXT [label2]
Indicates that after committing or undoing the transaction, the AVM executes the next iteration of the block you name with the label option. If you do not name a block with the NEXT option, the AVM executes the next iteration of the block with the ON QUIT phrase in its heading.
RETRY [label1]
Indicates that after committing or undoing the processing of a block, the AVM repeats the same iteration of the block that was undone or committed.
RETRY is the default if you do not specify 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 7. 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.