Try OpenEdge Now
skip to main content
Error Handling
Handling Errors with CATCH Blocks : System error message suppression with CATCH
 

System error message suppression with CATCH

The presence of a CATCH in an undoable block causes the AVM to suppress system error messages for all statements within the block, in the same way that the NO-ERROR option works on individual statements. If there is a CATCH on Progress.Lang.SysError, the messages will be added to the Progress.Lang.SysError object that is available in the CATCH. If there is no CATCH on Progress.Lang.SysError, and the Progress.Lang.SysError is not re-thrown (by way of ON ERROR UNDO, THROW on the block), the error messages from the Progress.Lang.SysError object will be written to the current output destination and the AVM will execute the ON ERROR phrase for the block.
In this example, a CATCH handles the error and the default error message is suppressed:
DEFINE VARIABLE myInt as INTEGER INITIAL 5.

DO ON ERROR UNDO, LEAVE:
FIND Customer WHERE CustNum=1000. /* raises ERROR and throws
                                        Progress.Lang.SysError
                                        Error message suppressed and
                                        execution goes to CATCH */

MESSAGE "After Find". /* won't get here */

CATCH eSysError AS Progress.Lang.SysError:
       MESSAGE "Inside CATCH block" VIEW-AS ALERT-BOX.
   /* Leave the CATCH, then the DO */
END CATCH.
END.
In this example, there is no CATCH block that handles the error and the error message is not suppressed:
DEFINE VARIABLE myInt as INTEGER INITIAL 5.

DO ON ERROR UNDO, LEAVE:
FIND Customer WHERE CustNum=1000. /* raises ERROR and displays
                                        "Customer record not on file. (138)"
                                        UNDO, LEAVE the block */

MESSAGE "After Find". /* won't get here */

CATCH ae AS Progress.Lang.AppError:
           MESSAGE ae:GetMessage(1) VIEW-AS ALERT-BOX.
   END CATCH.
END.