CATCH statement
- Last Updated: February 11, 2026
- 4 minute read
- OpenEdge
- Version 13.0
- Documentation
Defines a CATCH block, which allows you
to trap an error or stop object and write code to handle it.
A CATCH block can be referred to as an
end block because it defines end-of-block processing for the
block that encloses it. End blocks are always part of another block called the associated block. End blocks must appear in the associated block
after the last executable statement and before the END
statement. The other type of end block is the FINALLY
block.
The CATCH statement defines the start of
an end block that only executes if a condition is raised in its associated block and the
object type of the condition raised matches the class specified in the CATCH statement (or a subclass of that class). The CATCH block thus executes when an object of the specified error
or stop type is caught by the CATCH statement, at which point the object can then be handled in the CATCH block.
When the condition is raised, if there is an active transaction for the
associated block, the transaction is undone before the AVM begins executing the statements
within the CATCH block.
The CATCH block executes once for each iteration of its
associated block that raises a compatible error. A block can have multiple CATCH blocks, and all must come at the end of the associated
block.
There can only be one CATCH block for each
specific condition type in a block. However, the block also handles objects for its
subtypes. So, it is possible there can be more than one CATCH block that is compatible with a particular condition’s type. In this case,
the AVM executes the first CATCH block it encounters that
is compatible. For this reason, CATCH blocks should be
arranged from the most specific type to the most general.
CATCH blocks are covered in greater depth in ABL Error Handling.
Syntax
|
- object-variable
-
The variable name that references the object caught by this block. It is not necessary to define the object-variable ahead of time. The AVM recognizes a new variable name on the
CATCHstatement as a new object-variable definition within the current scope. EachCATCHin an associated block must have a unique object-variable. You can reuse an object-variable name in a different associated block, if its type is the same as the previous use. For all blocks with their own variable scope, such as object methods or internal procedures, aCATCHstatement inside that context may reuse the same variable name as aCATCHstatement outside of that context even if the type is different. - condition-class
- The code within a
CATCHblock only executes if a condition of type, condition-class (or a subtype), is raised within the body of the associated block. - catch-logic
- Any valid ABL statement. This typically contains a
MESSAGEstatement to display or log an error, or code to handle user-defined application conditions.
Examples
Example 1
In the following example, the CATCH block handles any ABL
system error.
|
Example 2
The following example illustrates how object-variable names can be reused.
|
Example 3
The following example illustrates using multiple CATCH blocks to handle
specific conditions.The CATCH block for the more specialized error classes
should come first.
|
Notes
- The use of
CATCHblocks is supported for all blocks, however it cannot be used in a simpleDOblock (one with no options). This is because the simpleDOblock does not have implicit error handling capabilities. You will get a compiler error if you try.DOblocks must have an explicitTRANSACTION, ON ERROR UNDO, orON STOPdirective, in order to have aCATCHblock. - If a
FINALLYblock is used at the end of an associated block, it must come after anyCATCHblocks. For more information onFINALLYblocks see ABL Error Handling. - The compiler issues a warning message if a block contains a
CATCHblock that is not reachable. For example, if you have aCATCHblock forProgress.Lang.AppErrorfollowed by aCATCHblock for a subtype ofProgress.Lang.AppError, you get a compiler warning. - Using
NO-ERRORon a statement prevents aCATCHblock from executing if the statement raises a condition. The general error handling precedence, from highest to lowest, is the following:- Statement
NO-ERRORoption CATCHblock- Block's
ONphrase (explicit or implicit)
CATCHblocks see ABL Error Handling. - Statement
- The
CATCHblock is an undoable block with implicitON ERROR UNDO, THROWerror handling. You cannot explicitly override theON ERRORdirective for aCATCHblock. - A
CATCHblock within aCATCHblock only handles errors raised within theCATCHblock. To prevent infinite looping, the implicit or explicitUNDO, THROWstatement within the top-levelCATCHblock, or anyCATCHblock nested within it, immediately throws the error to the block that encloses the associated block of the top-levelCATCHblock. For more detail, see ABL Error Handling. - The ability to throw and catch
Progress.Lang.Stop(and it's subclasses) orProgress.Lang.StopErrorobjects is the default in 12.0. To turn this off you must have the Catch STOP (-catchStop) startup parameter set to the value0(-catchStop 0). If a value of 0 is specified, the AVM raises theSTOPcondition only, without throwing the associated object. - Class-based error or stop objects can be thrown from an OpenEdge
application server and handled by a
CATCHblock on an ABL client. To be thrown, any user-defined error classes must be defined, on both the server and client sides, asSERIALIZABLE. For more information on throwing error objects from an application server to an ABL client, see ABL Error Handling.
See also
BLOCK-LEVEL ON ERROR UNDO, THROW statement, ON ERROR phrase, ON STOP phrase, Progress.Lang.Error interface, Progress.Lang.Stop class, RETURN statement, ROUTINE-LEVEL ON ERROR UNDO, THROW statement, UNDO statement