Describes the processing that occurs when there is an error in a block. If you are using a REPEAT block or a FOR EACH block, and an error occurs, all of the processing that has been done in the current iteration of the block is undone, and the AVM retries the block iteration where the error occurred. (If the AVM detects that a RETRY of a FOR or iterating DO block would produce an infinite loop, it performs a NEXT instead. For more information, see OpenEdge Getting Started: ABL Essentials.
ON ERROR UNDO [label1] [ , LEAVE [ label2 ] | , NEXT [ label2 ] | , RETRY [ label1 ] | , RETURN [ return-value | ERROR [ return-value | error-object-expression ] | NO-APPLY ] | , THROW ] |
RETRY is the default processing if you do not use LEAVE, NEXT, RETRY, or RETURN.
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. |
ERROR | Raises ERROR in the caller and undoes the current subtransaction. |
ERROR return-value | Raises ERROR in the caller and undoes the current
subtransaction. The CHARACTER string you provide is passed to the
caller. The caller can use the RETURN-VALUE function to read the returned
value. The AVM also creates an Progress.Lang.AppError object and stores the return-value in the ReturnValue property. Note: User-defined functions have different behavior
since they must return the data type specified in the definition.
See the FUNCTION statement for
more information.
|
ERROR error-object-expression | Raises ERROR in the caller and undoes the current
subtransaction. The specified error object is created and populated according to your code. If this is an Progress.Lang.AppError object, the caller can 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. |
You cannot specify ERROR within a user-interface trigger block or a destructor. You can specify the NO-APPLY option only within a user-interface trigger block.
For example, assume you have an enclosing block with a set of CATCH blocks for handling your error types. Within this block is another block with the ON ERROR UNDO, THROW directive. THROW forces any error in this block to the enclosing block.
If there is an CATCH block within the block with the THROW directive and that CATCH explicitly handles the THROWN error, then the error is not propagated to the enclosing block. In this case, the explicit CATCH block handles the error. The THROW directive only applies to errors that are not explicitly caught.
When used, system error messages generated by statements in the block are suppressed and diverted to a Progress.Lang.SysError object. Any error (SysError, AppError, or user-defined) raised within that block will result in an UNDO of the work in that block's iteration as long as there is an active transaction. The error object is thrown to the next enclosing block.
In r-onerr.p, if you enter a Customer number and the FIND statement is unable to find a Customer with that number, the AVM raises an error. If an error occurs, the ON ERROR phrase tells the AVM to undo anything that was done in the current iteration and start the next iteration. Thus, you see any invalid numbers you enter, and you can continue to the next Customer number you want to enter.
r-onerr.p
REPEAT ON ERROR UNDO, NEXT: PROMPT-FOR Customer.CustNum. FIND Customer USING Customer.CustNnum. DISPLAY Customer.Name Customer.Address Customer.City Customer.State Customer.Country. END. |
This block propagates an error from a DO block up to the main procedure block. A CATCH block on the main procedure block handles the error.
r-onErrorThrow01.p
DO ON ERROR UNDO, THROW: /* Raises ERROR. The normal error message is diverted to a Progress.Lang.SysError error object and thrown to the main block. */ FIND Customer 1000. END. /* DO */ MESSAGE "Undisplayed message because of ERROR condition" VIEW-AS ALERT-BOX BUTTONS OK. /* CATCH for main (procedure) block */ CATCH eAnyError AS Progress.Lang.ERROR: MESSAGE "Error message and number retrieved from error object..." eAnyError:GetMessage(1) eAnyError:GetMessageNum(1) VIEW-AS ALERT-BOX BUTTONS OK. END CATCH. |