PreviousNextIndex

CATCH statement

Defines an error-handling end block for any undoable ABL block. An end block is an ABL block that can occur only within another block. The block containing the end block is known as the associated block. End-blocks must occur between the last line of executable code in the associated block and the END statement.

The CATCH end block executes when an error raised in the associated block is compatible with the error type specified in the CATCH block. To be compatible, the error type must be the error type specified in the CATCH statement, or it must be a sub-type (sub-class) of the specified type. CATCH blocks take precedence over any implicit or explicit ON ERROR directives for the associated block. This is the syntax for the CATCH statement and its related blocks:

Syntax

block-statements 
    CATCH error-variable AS [ CLASS ] error-class: 
        catch-logic 
    END [ CATCH ] . 
[ block-end-statement ] 

block-statements
error-variable
[ CLASS ] error-class
catch-logic
block-end-statement
Examples

The following code fragment shows CATCH blocks for associated DO blocks:

DO ON ERROR UNDO, LEAVE: 
  FIND FIRST Customer NO-LOCK WHERE Customer.CustNum = 5000. 
  CATCH oneError AS Progress.Lang.SysError: 
    MESSAGE oneError:GetMessage(1) VIEW-AS ALERT-BOX BUTTONS OK. 
  END CATCH. 
  CATCH twoError AS Progress.Lang.ProError: 
    MESSAGE twoError:GetMessage(1) VIEW-AS ALERT-BOX BUTTONS OK. 
  END CATCH. 
END. /* FIRST DO */ 
DO ON ERROR UNDO, LEAVE: 
  FIND FIRST Customer NO-LOCK WHERE Customer.CustNum = 6000. 
  /* You can reuse an error-variable from a different associated block */ 
  CATCH oneError AS Progress.Lang.SysError: 
    MESSAGE oneError:GetMessage(1) VIEW-AS ALERT-BOX BUTTONS OK. 
  END CATCH. 
  /* NOT LEGAL: Each CATCH block in an associated block must have a unique 
     error-variable. */ 
  CATCH oneError AS Progress.Lang.ProError: 
    MESSAGE oneError:GetMessage(1) VIEW-AS ALERT-BOX BUTTONS OK. 
  END CATCH. 
END. /* SECOND DO */ 

In the following example, the CATCH block will catch any ABL system error:

DEFINE VARIABLE iCust AS INTEGER NO-UNDO INITIAL 5000. 
FIND Customer NO-LOCK WHERE Customer.CustNum = iCust. /* Will fail */ 
/* Won't execute because FIND fails */ 
MESSAGE "Customer found" VIEW-AS ALERT-BOX BUTTONS OK.  
/* The associated block for this CATCH block is the main block of the .p */ 
CATCH eSysError AS Progress.Lang.SysError: 
  MESSAGE eSysError:GetMessage(1) VIEW-AS ALERT-BOX BUTTONS OK. 
END CATCH. 

Notes
See also

ON ERROR phrase, RETURN statement, ROUTINE-LEVEL ON ERROR UNDO, THROW statement, UNDO statement


OpenEdge Release 10.2B
Copyright © 2009 Progress Software Corporation
PreviousNextIndex