UNDO statement
Backs out all modifications to fields and variables made during the current iteration of a block, and indicates what action to take next.
Syntax
label
The name of the block whose processing you want to undo. If you do not name a block withlabel1
, UNDO undoes the processing of the closest transaction or subtransaction block. In determining the closest transaction or subtransaction block, the AVM disregards DO ON ENDKEY blocks that do not have the ON ERROR or TRANSACTION option.LEAVElabel2
NEXTlabel2
RETRYlabel1
Indicates that after undoing the processing of a block, the AVM repeats the same iteration of the block you name withlabel1
. If you name a block withlabel1
it must be the name of the block that was undone.RETRY is the default processing if you do not use LEAVE, NEXT, RETRY, or RETURN. When a block is retried, any frames scoped to that block are not advanced or cleared.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:
Option Descriptionreturn-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. ERRORreturn-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 anProgress.Lang.AppError
object and stores thereturn-value
in theReturnValue
property.Note: User-defined functions have different behavior since they must return the data type specified in the definition. See the "FUNCTION statement" section for more information. ERRORerror-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 anProgress.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.THROWerror-object-expression
The THROW directive stops the execution of the current block of ABL code, or the current iteration of an ABL iterating block, and raises the error type specified inerror-object-expression
. The value oferror-object-expression
is an error object.In this example, the THROW directive creates an instance of Progress.Lang.AppError using one of the default object constructors:
You can only THROW error objects, and an error object is an object derived from the built-in interface Progress.Lang.Error. It is a compile-time error to THROW an object that is not derived from Progress.Lang.Error.When the THROW occurs, execution stops, and the specified error is raised. The error should then be handled by the NO-ERROR qualifier, a CATCH block, or by an explicit or implicit ON ERROR phrase.The following notes describe restrictions on using UNDO, THROW:
- If the action on the UNDO statement is THROW, the UNDO cannot have a [label]. To do so will result in a compile-time error.
- UNDO, THROW is not allowed in a CATCH block associated with the main block of an object destructor method. You cannot raise or RETURN an error from a destructor. To do so will result in a compile-time error. You can use UNDO, THROW within the code of the destructor itself. In this case, the statement will raise error in the destructor block and be caught by the ON ERROR directive of the destructor block (which can only be UNDO, LEAVE).
- UNDO, THROW is not allowed in a CATCH block of a user interface trigger. The ABL does not you to raise or RETURN error out of a user interface trigger. To do so will result in a compile-time error.
- The UNDO, THROW statement can itself raise error or THROW a Progress.Lang.SysError object if it fails. For example, if the statement cannot find the specified error object. In this case, the SysError will be trapped by the same block that would have trapped the successfully thrown error object.
ExamplesThe
r-undo.p
procedure prompts you for the initials of a sales representative. If the initials match those of an existing sales representative, the procedure displays that sales representative’s record. Otherwise, it prompts you to add another sales representative with the initials you supplied. If you enter no, the UNDO statement undoes the work you have done since the start of the REPEAT block and lets you enter another set of initials.
This example shows how the UNDO, THROW statement specifies and populates an error object, and how the CATCH block handles it:
Notes
- You can also specify UNDO processing for a block by using the ON ERROR and ON ENDKEY phrases with a block statement.
- An UNDO statement that specifies a block that encompasses the current system transaction block has no effect on changes made prior to the start of the system transaction. This includes changes made to variables prior to the beginning of the system transaction.
- If nothing changes during a RETRY of a block, then the RETRY is treated as a NEXT or a LEAVE. This default action provides protection against infinite loops.
- For more information on the UNDO statement, see OpenEdge Getting Started: ABL Essentials.
See alsoON ENDKEY phrase, ON ERROR phrase, RETRY function, RETURN statement, ROUTINE-LEVEL ON ERROR UNDO, THROW statement
OpenEdge Release 10.2B
|