Try OpenEdge Now
skip to main content
Error Handling
Using ABL Error Classes : Progress.Lang.AppError class : Example
 

Example

This section provides the class file of an AppError subclass and a procedure that demonstrates how to use the AppError methods.
This is the code for the class file (.cls):
CLASS MyAppError2 INHERITS Progress.Lang.AppError:

DEFINE VARIABLE lastmsg AS INTEGER NO-UNDO.

    CONSTRUCTOR PUBLIC MyAppError2( ):
        SUPER().
    END CONSTRUCTOR.

    CONSTRUCTOR PUBLIC MyAppError2(mymsg AS CHARACTER, mynum AS INTEGER):
        AddMessage(mymsg, mynum).
        MESSAGE "In MyAppError2 Char & Int Constructor" mymsg mynum.
    END CONSTRUCTOR.

CONSTRUCTOR PUBLIC MyAppError2(mynum AS INTEGER):
MESSAGE "In MyAppError2 Integer Constructor" mynum.
END.

DESTRUCTOR PUBLIC MyAppError2():
MESSAGE "In MyAppError2 destructor" .
END DESTRUCTOR.

END CLASS.
Notice the constructors provide messages. When an instance of the new class is created, these messages will appear in the run-time message area of the procedure window.
This is the code for the procedure:
/* *************************** Definitions ************************** */
DEFINE VARIABLE i AS INTEGER NO-UNDO.
DEFINE VARIABLE myaerr AS CLASS MyAppError2 NO-UNDO.
DEFINE VARIABLE mynm AS INTEGER NO-UNDO.

/* *************************** Main Block *************************** */

DO ON ERROR UNDO, LEAVE:
RUN intproce.

CATCH mae AS MyAppError2:
MESSAGE "Inside MyAppError2 Catch".
ASSIGN mynm = mae:NumMessages.
MESSAGE "Number of messages" mynm .
REPEAT i = 1 TO mae:NumMessages:
MESSAGE "Error Number: " mae:GetMessageNum(i) SKIP
"Message: " mae:GetMessage(i) SKIP
"NumMessage: " i .
END.

MESSAGE "Here is the ReturnValue " mae:ReturnValue .
  END CATCH.
END.

DO ON ERROR UNDO, LEAVE:
RUN removeall.

CATCH mae AS MyAppError2:
MESSAGE "Inside MyAppError2 Catch".
ASSIGN mynm = mae:NumMessages.
MESSAGE "Number of messages" mynm .
REPEAT i = 1 TO mae:NumMessages:
MESSAGE "Error Number: " mae:GetMessageNum(i) SKIP
"Message: " mae:GetMessage(i) SKIP
"NumMessage: " i .
END.

MESSAGE "Here is the ReturnValue " mae:ReturnValue .
END CATCH.
END.

/* Internal Procedures */
PROCEDURE intproce:
MESSAGE "In intproce" .
myaerr = NEW MyAppError2("ConstMsg", 100).
myaerr:AddMessage("Error in Internal Proc", 101).
myaerr:AddMessage("SecondMsg", 102).
myaerr:AddMessage("ThirdMsg", 103).
myaerr:AddMessage("FourthMsg", 104).
REPEAT i = 1 TO myaerr:NumMessages:
MESSAGE "Error Number: " myaerr:GetMessageNum(i) SKIP
"Message: " myaerr:GetMessage(i) SKIP
"NumMessage: " i .
END.
myaerr:RemoveMessage(2).
myaerr:RemoveMessage(3).
myaerr:ReturnValue = "Add and Remove Msg case 66".
RETURN ERROR myaerr.
END.

PROCEDURE removeall.
MESSAGE "In Removeall" .
myaerr = NEW MyAppError2("ConstMsg", 200).
myaerr:AddMessage("Error in Internal Proc", 201).
myaerr:AddMessage("SecondMsg", 202).
myaerr:AddMessage("ThirdMsg", 203).
myaerr:AddMessage("FourthMsg", 204).
REPEAT i = 1 TO myaerr:NumMessages:
MESSAGE "Error Number: " myaerr:GetMessageNum(i) SKIP
"Message: " myaerr:GetMessage(i) SKIP
"NumMessage: " i .
END.
myaerr:RemoveMessage(5).
myaerr:RemoveMessage(4).
myaerr:RemoveMessage(3).
myaerr:RemoveMessage(2).
myaerr:RemoveMessage(1).
myaerr:ReturnValue = "Add and Remove All Msg case 66".
RETURN ERROR myaerr.
END PROCEDURE.