ON STOP phrase
- Last Updated: January 18, 2024
- 4 minute read
- OpenEdge
- Version 12.8
- Documentation
Describes processing that occurs when the STOP condition
is raised. The STOP condition is raised when:
- The user presses the STOP key (usually mapped to CTRL+BREAK in Windows and CTRL+C on Unix/Linux.)
- The time-out is exceeded for a
STOP-AFTERdirective on aDO,FOR, orREPEATstatement. - The time-out set using the Lock Timeout (
-lkwtmo) startup parameter is exceeded when waiting for release of a record lock, or when the user indicates they want to stop waiting. - A
STOPstatement executes. - System errors occur that raise the
STOP(instead of theERROR) condition.
By default, when a STOP condition
occurs in a block, all the changes to persistent data (database fields) are undone. If the
block is a transaction block, undo variables and temp-table fields are also undone. See
Develop ABL Applications for more information on transaction
blocks. The ON STOP phrase can be used to modify the scope
of UNDO processing, possibly widening it to an outer
block.
Also by default, a STOP condition causes execution to
leave the current block. The STOP condition is continually propagated to
the outer block, or up the call stack if there is no outer block. The ON
STOP phrase can be used to control where execution continues and to clear the
STOP condition so that it is not propagated beyond the current block.
The AVM performs stop handling using this precedence, from highest to
lowest. The AVM only abides by one of these when a STOP is raised:
CATCHblock- Block’s
ONphrase (explicit or implicit)
Due to this precedence, the ON STOP
phrase is ignored if a local CATCH block handles the
stop.
Syntax
|
- label1
- The name of the block whose processing you want to undo. If you do not name a block with label1, the AVM undoes the processing of the current block.
- 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 current block. There are restrictions. For example, you cannot undo an outer block, but leave only the inner block.
- 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
NEXToption, the AVM executes the next iteration of the current block. - RETRY [label1]
- Indicates that after undoing the processing of a block, the AVM
repeats the same iteration of the block.
Because
RETRYin a block without user input results in an infinite loop, the AVM automatically checks for this possibility and converts aRETRYblock into aLEAVEblock, or aNEXTblock if it is an iterating block. This behavior is often referred to as infinite loop protection. - RETURN ...
- Returns to the calling routine, if there is one. The following table
describes various
RETURNoptions:Option Description return-value In procedures and VOID methods, this must be a CHARACTER string. The caller can use the RETURN-VALUEfunction to read the returned value. For user-defined functions, non-VOID methods and property getters, the value must match the specified return type.ERRORUndoes the current subtransaction, and raises ERRORin the caller. You cannot specifyERRORwithin a user-interface trigger block or a destructor.For user-defined functions see note below.
ERRORreturn-valueUndoes the current subtransaction, and raises ERRORin the caller. The CHARACTER string you provide is available to the caller in theRETURN-VALUEfunction. The AVM also creates anAppErrorobject and stores the return-value in theReturnValueproperty.For user-defined functions see note below.
ERRORerror-object-expressionUndoes the current subtransaction, and raises ERRORin the caller. The specified error object instance is thrown to the caller.For user-defined functions see note below.
NO-APPLYIn a user-interface trigger, prevents the AVM from performing the default behavior for the trigger event. Otherwise, the option is ignored. Note: UsingRETURN ERRORin a user-defined function sets the target variable of the function to the Unknown value (?) instead of raisingERRORin the caller. See ABL Error Handling for more detail.
Example
This procedure lets you update the CreditLimit field for each Customer. If you enter a value greater than 100,000,
the program raises the STOP condition. Since you specified
an UNDO, RETRY for a STOP, the procedure starts the iteration over and allows you to enter another
value.
r-ostop.p
|
Notes
- When both a local
ON STOPphrase and a matching localCATCHblock is specified on the current block, the localCATCHblock takes precedence and theON STOPphrase is ignored. If no localCATCHblock matches the thrown stop object type, the specified directive in the localON STOPphrase executes instead for any raisedSTOPcondition. - Almost all
STOPconditions are trappable with theON STOPphrase or aCATCHblock. In some cases, the AVM might ignoreSTOPconditions at certain levels of the call stack. For example, if the AVM executes a procedure that relies on a database and the connection is lost, the AVM raises theSTOPcondition and unwinds the call stack until it gets to a level above all references to the database.ON STOPphrases and compatibleCATCHblocks before this point are ignored. After this point, the AVM executes the directive specified in theON STOPphrase or compatibleCATCHblock, with theCATCHblock taking precedence if theON STOPphrase is on the same associated block. - If a block does not have implicit error handling capabilities (for example, a simple
DOorDO WHILEblock) you can add theON STOP(orON ERROR) phrase to explicitly turn it into one with error handling. This allows you to use aCATCHstatement within the block to catch any error or stop conditions. If you don't add theON STOP(orON ERROR) phrase and try to use aCATCHwithin the block, you get a compiler error.
See also
CATCH statement, ON ENDKEY phrase, ON ERROR phrase, ON QUIT phrase, Progress.Lang.Stop class, Progress.Lang.StopError class, RETURN statement, RETURN-VALUE function, STOP statement