BLOCK-LEVEL ON ERROR UNDO, THROW statement
- Last Updated: July 26, 2022
- 3 minute read
- OpenEdge
- Version 12.2
- Documentation
BLOCK-LEVEL ON ERROR UNDO, THROW statement
Use this statement in a procedure (.p) or class (.cls) file to change the
default ON ERROR directive to ON ERROR UNDO, THROW for
all blocks that have a default error directive associated with them. (A simple DO block, for
example, does not have default error handling and is not affected by this statement.). This
is specifically for ERROR, not STOP conditions because
STOP conditions are already thrown by default. The statement must come
before any executable or DEFINE statements in a file. However, it can come
either before or after a USING statement.
Syntax
|
This statement affects the following block types:
- Procedure (also called main block, external procedure, or .p file, including database trigger .p files)
- Internal procedures
- User-defined functions
- Methods of a class
- Class constructors
- Property accessors
ONblocks used as database triggers withCREATE,DELETE,WRITEorASSIGNeventsREPEATblocksFORblocksDO TRANSACTIONblocks
This statement does not affect:
- Destructors
- Error directives that are explicitly coded in individual, non routine-level blocks
ONblocks that are UI triggers.
Note these alternatives to the BLOCK-LEVEL ON ERROR UNDO,
THROW statement:
- Instead of adding the statement to source-code files, you can use the
-undothrow 2startup parameter to change the default error-handling toUNDO, THROWon every block affected by theBLOCK-LEVELstatement during compilation. See the Startup Command and Parameter Reference for more information. - The ROUTINE-LEVEL ON ERROR UNDO, THROW statement
can be used if you want to change the default error-handling only on routine-level blocks.
(You can use the
-undothrow 1startup parameter to change the default error handling on routine-level blocks toUNDO, THROWduring compilation.)
Example
An error propagates from the DO TRANSACTION block to the
internal procedure, from the internal procedure up to the main .p file (b-BLOCK-LEVEL-01.p), and finally up to the
CATCH block in the calling .p file (b-BLOCK-LEVEL-02.p). An error is raised at each of these levels. At each level
the ON ERROR UNDO, THROW directive takes effect.
b-BLOCK-LEVEL-01.p
|
b-BLOCK-LEVEL-02.p
|
Notes
- The
BLOCK-LEVEL ON ERROR UNDO, THROWstatement guarantees that all unhandled errors in affected blocks are propagated up to the caller. You can decide whether to handle errors at the block level with aCATCHstatement, or to handle all errors with aCATCHblock at a higher level. - The
BLOCK-LEVELstatement affects the same blocks as the ROUTINE-LEVEL ON ERROR UNDO, THROW statement, plusREPEAT,FOR, andDO TRANSACTIONblocks. Therefore, there is no need to add both statements to a file. If both statements exist in a file, the more inclusiveBLOCK-LEVELstatement takes precedence. - Error objects can be thrown from an application server and handled by a
CATCHblock on an ABL client. To be throwable from an application server to an ABL client, user-defined error classes must be defined on both the server and client sides, and the classes must be defined asSERIALIZABLE. For the full list of restrictions on class-based objects that are passed between application server and client, see the Parameter passing syntax entry. For more information on error handling in general, see ABL Error Handling.
See also
ON ENDKEY phrase, ON ERROR phrase, ON QUIT phrase, RETURN statement, RETURN-VALUE function, ROUTINE-LEVEL ON ERROR UNDO, THROW statement, STOP statement, UNDO-THROW-SCOPE attribute