Property error handling example
- Last Updated: March 30, 2020
- 1 minute read
- OpenEdge
- Version 12.2
- Documentation
Property error handling example
The following code fragment from the sample class, acme.myObjs.CreditObj,
shows an example of property error handling:
|
This class defines the CustCreditLimit property to
set the credit limit for the current Customer record, depending
on the customer’s credit standing. The SET accessor
raises ERROR by throwing an application error object
if the customer’s balance is over their current credit limit, by
first setting the property value to that current limit, then creating
the error object with a constructor that specifies an error return
string ("Over Limit") to indicate this condition.
For this error condition, note also that the SET accessor
retains its setting because the property is defined as NO-UNDO,
and it automatically throws the error object out of the accessor
block to (raises ERROR on) the statement that sets
the property value because the class is defined with the ROUTINE-LEVEL
ON ERROR UNDO, THROW statement. However, if the customer’s
credit standing is good, the SET accessor immediately
raises the customer’s credit limit and sets the property with that
new value.
So, as defined in the same class, the CheckCustCredit( ) method sets the
CustCreditLimit property with the customer’s current credit limit and
automatically re-throws any error object to the caller that is thrown from setting the
property value. This error object is, in turn, caught and checked by the
CheckCredit( ) method in the sample class,
acme.myObjs.CreditObj.