Method error handling example
- Last Updated: December 9, 2013
- 1 minute read
- OpenEdge
- Version 13.0
- Documentation
Method error handling example
The following class fragments from the sample classes show an example of method error handling:
|
The CheckCustCredit( ) method of acme.myObjs.CreditObj throws
an error object for two different conditions, which are distinguished
by the error return string returned in the ReturnValue property
of the Progress.Lang.AppError object. Note that
the object returning the "No Customer" string is
created using the NEW function, and another error
object containing the "Over Limit" can be thrown
from an error condition raised in the SET accessor
of the CustCreditLimit property (see the code for
this property in the ). The ROUTINE-LEVEL ON ERROR UNDO,
THROW statement that begins the class definition ensures
that any error objects not caught and consumed by methods of the
class are thrown to a method’s caller.
Also note that to make a Customer record available, the SetCurrentCustomer( ) method
must be successfully invoked prior to invoking CheckCustCredit( ). SetCurrentCustomer( ) relies
on the NO-ERROR option of a FIND statement
to complete with an error raised because no record is found with
the specified criteria. So, instead of using structured error handling
for this situation in both methods, CheckCustCredit( ) checks
for record availability to handle that particular error.
The CheckCredit( ) method of acme.myObjs.CustObj then
invokes these methods in the correct sequence and, if ERROR is
raised, checks the value of the ReturnValue property
on the error object to handle the error condition appropriately,
as shown:
|