Try OpenEdge Now
skip to main content
Error Handling
Introduction to Condition Handling : Structured error handling : What is ABL structured error handling?
 

What is ABL structured error handling?

Since ABL is a block structured language, ABL has no need for a block-making construct like the try statement. ABL blocks have something more than simple try blocks. Because ABL is a language with database semantics, all ABL blocks are undoable blocks that protect the database by undoing work when a block fails. This ability means you have more options for successfully resuming execution after an error. For example, you could retry a block after an error.
All blocks have implicit error handling of some type, except for the simple DO block (a DO ... END block without transaction or error handling options). Explicit error handling for blocks is provided by an ON ERROR phrase and its many options. Default error handling is provided by an implicit ON ERROR phrase. Implicit and explicit ON ERROR phrases make up, in brief, traditional error handling.
ABL adds built-in classes to represent errors as objects and a CATCH statement. These changes provide the basic mechanics of structured error handling in ABL. Here is a simple example:
DO ON ERROR UNDO, RETURN:

FIND FIRST Customer WHERE CustNum = 1000.

CATCH eSystemError AS Progress.Lang.SysError:
MESSAGE "Not a valid customer number.".
       UNDO, THROW eSystemError.
    END CATCH.

END. /* DO */
The explicit ON ERROR phrase defines error handling for the block. In traditional error handling, the RETURN action occurs if any error is raised within the block. In structured error handling, the RETURN action occurs for any error that is not explicitly handled by a CATCH block. Since the FIND statement fails and raises a system error, the CATCH block executes and the MESSAGE statement displays a customer error message in the message area of the procedure window. However, the CATCH block concludes with the UNDO, THROW statement that directs the block enclosing the DO block to handle the eSystemError object. The enclosing block is the main procedure block, which by default uses traditional error handling. So, the default error message will also appear in a message block when the error object is thrown to the main procedure block. This demonstrates how error handling moves seamlessly between traditional and structured error handling.