PreviousNextIndex

ROUTINE-LEVEL ON ERROR UNDO, THROW statement

Use this statement in a procedure (.p) or class (.cls) file to change the default ON ERROR phrase associated with routine-level blocks and ON blocks used as database triggers.

Syntax

ROUTINE-LEVEL ON ERROR UNDO, THROW. 

The undoable blocks (DO, FOR, and REPEAT), support the ON ERROR UNDO, THROW phrase. This phrase is useful for propagating errors up the call stack where they can be handled by CATCH blocks associated with higher level blocks. This technique eliminates the need for CATCH blocks handling common error types at every level in a series of nested blocks.

The main blocks of ABL routines do not support explicit ON ERROR phrases. The following blocks are called routine-level blocks:

The routine-level blocks have an implicit, default ON ERROR UNDO, RETRY phrase (with infinite loop protection). Therefore, you cannot change the default behavior for routine-level blocks to throw or re-throw errors with the ON ERROR phrase.

The ROUTINE-LEVEL ON ERROR UNDO, THROW statement for class (.cls) and procedure (.p) files changes the default implicit ON ERROR phrase to ON ERROR UNDO, THROW for every routine-level block contained in the file.

Similarly, when an ON block is a database trigger with a CREATE, DELETE, WRITE or ASSIGN event, the ROUTINE-LEVEL ON ERROR UNDO, THROW statement changes the implicit ON ERROR phrase to ON ERROR UNDO, THROW.

The following are rules affecting the placement of this statement:

Example

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-ROUTINE-LEVEL-01.p
ROUTINE-LEVEL ON ERROR UNDO, THROW. 
PROCEDURE find1000: 
  FIND FIRST Customer WHERE Customer.CustNum = 1000. 
END PROCEDURE. 
PROCEDURE find2000: 
  FIND FIRST Customer WHERE Customer.CustNum = 2000. 
END PROCEDURE. 
PROCEDURE find3000: 
  FIND FIRST Customer WHERE Customer.CustNum = 3000. 
END PROCEDURE. 
/* Main Block */ 
RUN find1000. 
RUN find2000. 
RUN find3000. 
CATCH eAnyError AS Progress.Lang.SysError: 
  MESSAGE "Your CATCH block associated with the the main block (.p) has handled 
an error in an internal procedure." 
    VIEW-AS ALERT-BOX BUTTONS OK. 
END CATCH. 

Notes
See also

ON ENDKEY phrase, ON ERROR phrase, ON QUIT phrase, RETURN statement, RETURN-VALUE function, STOP statement


OpenEdge Release 10.2B
Copyright © 2009 Progress Software Corporation
PreviousNextIndex