PreviousNextIndex

ON ERROR phrase

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.

Syntax

ON ERROR UNDO 
  [ label1 ] 
  [     , LEAVE [ label2 ] 
     |  , NEXT [ label2 ] 
     |  , RETRY [ label1 ] 
     |  , RETURN [ return-value | 
                  ERROR [ return-value | error-object-expression ] | 
                  NO-APPLY ]  
     |  , THROW  
  ] 

label1
LEAVE [ label2 ]
NEXT [ label2 ]
RETRY [ label1 ]
RETURN ...
THROW
Examples

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. 

Notes
See also

ON ENDKEY phrase, ON QUIT phrase, ON STOP phrase, RETURN statement, RETURN-VALUE function, ROUTINE-LEVEL ON ERROR UNDO, THROW statement, UNDO statement


OpenEdge Release 10.2B
Copyright © 2009 Progress Software Corporation
PreviousNextIndex