Try OpenEdge Now
skip to main content
Error Handling
Using Structured Error Handling : Structured error handling tasks
 

Structured error handling tasks

Another way to introduce structured error handling is to look at a list of additional tasks you need to know how to do. The following table expands on the list presented in Traditional versus structured error handling table.
Table 9. Structured error handling tasks
Task
Description
Know how to reference an error object and access its properties and methods
Define an instance variable and type (class name) in the CATCH block header. Use the instance variable to access the properties and methods.
Know how to subclass the built-in application error class (optional)
Structured error handling lets you define your own application error objects using the full set of object-oriented programming features. Application error objects must be a subclass of Progress.Lang.AppError. This task requires a working knowledge of object-oriented programming in ABL.
Know how to explicitly raise an error (THROW)
The THROW option is another branching directive like NEXT or LEAVE. It is available in all the places that the other directives are available.
Know how to handle a particular error and how to handle different errors within a block
Each error type you need to handle differently in a block requires a different CATCH block. Since the first compatible CATCH block found is used, organize CATCH blocks from most specific to least specific.
Know how to pass (re-THROW) error objects from an inner block to an outer block
Once you catch an error object, you can use the THROW directive to pass it to the enclosing block. That block can re-throw the error to the next enclosing block, and so on.
Know how to propagate errors up the call stack automatically
The BLOCK-LEVEL ON ERROR UNDO, THROW and ROUTINE-LEVEL ON ERROR UNDO, THROW statements and the -undothrow startup parameter let you make THROW the default directive on a per-file or per-application basis, facilitating centralized error handling by propagating errors upward.
Know the precedence of error-handling mechanisms
When an error occurs, the AVM looks for an error handler using this precedence, from highest to lowest:
*Statement NO-ERROR option
*CATCH block
*Explicit ON ERROR phrase
*Implicit ON ERROR phrase
Know how to return an error from a user-defined function
User-defined functions do not raise ERROR after a RETURN ERROR statement. However, using the THROW directive you can do this with structured error handling.
Know how to perform optional end-of-block processing
The FINALLY end block is a useful ABL feature for more than just error handling. The FINALLY block executes at the completion of each iteration of a block whether the execution was successful or raised ERROR.