Try OpenEdge Now
skip to main content
Error Handling
Raising errors with THROW : THROW as a default for blocks : BLOCK-LEVEL ON ERROR UNDO, THROW statement : Example
 
Example
To create an application that uses structured error handling to handle all uncaught local errors at the top level:
*Include the BLOCK-LEVEL ON ERROR UNDO, THROW statement in all your procedure and class files.
*Add a CATCH block for the Progress.Lang.Error interface to your startup procedure block.
*For each basic block, decide whether or not an explicit THROW is appropriate for that block.
This example is simple but illustrates the design pattern:
BLOCK-LEVEL ON ERROR UNDO, THROW.

PROCEDURE find1000:
/* Ignore potential errors */
FIND FIRST Customer WHERE CustNum = 1000 NO-ERROR.
END PROCEDURE.

PROCEDURE find2000:
FIND FIRST Customer WHERE CustNum = 2000.

CATCH eSysError AS Progress.Lang.SysError:
/* Take care of this error locally */
END CATCH.
END PROCEDURE.

PROCEDURE find3000:
    FIND FIRST Customer WHERE CustNum = 3000.
END PROCEDURE.

/* Main Startup Procedure Block */

RUN find1000.
RUN find2000.
RUN find3000.

/* Won't execute */
MESSAGE "Application completed execution successfully."
VIEW-AS ALERT-BOX BUTTONS OK.

CATCH eAnyError AS Progress.Lang.Error:
MESSAGE "Unexpected error occurred..." SKIP
"Logging information..." SKIP
"Exiting application..."
VIEW-AS ALERT-BOX BUTTONS OK.
QUIT.
END CATCH.