The ERROR-STATUS system handle allows you to test whether any error occurs and whether a particular error occurs. You can have a branch that executes for a particular error, and you can have another branch that executes for any other error.

The attributes and methods of the handle allow you to access the error message strings and error numbers. If specific errors are important to you, the error numbers are useful. But more often than not, you are simply interested in whether an error occurs.

The following table describes the significant attributes and methods of the ERROR-STATUS system handle.

Attribute or method Description
ERROR attribute If the ABL statement uses the NO-ERROR option and the AVM raises the ERROR condition, this attribute is set to TRUE.

Some handle methods may generate an error message but not raise ERROR. In this case the condition is treated as a warning and the attribute remains FALSE. However ERROR-STATUS:NUM-MESSAGES is still set to a nonzero value. See Handle warnings for more detail.

ERROR-OBJECT-DETAIL attribute If a Web service method returns a SOAP fault, the AVM stores the SOAP fault information in an ABL SOAP-fault object and raises ERROR. The AVM stores a handle reference to the SOAP-fault object in this attribute.
NUM-MESSAGES attribute Provides an integer count of all the error messages generated by the statement with the NO-ERROR option.
GET-MESSAGE(index)method Allows you to retrieve the specified error string. The index runs from 1 to the value of NUM-MESSAGES.
GET-NUMBER(index) method Allows you to retrieve the specified error number. The index runs from 1 to the value of NUM-MESSAGES.

The following example illustrates using the FIND statement with NO-ERROR:

METHOD PUBLIC DECIMAL getCustomerBalance(custName AS CHAR):

    FIND FIRST Customer WHERE Customer.NAME = custName NO-ERROR. 
    IF ERROR-STATUS:ERROR THEN 
        RETURN ERROR. // No Customer found with that name 
    ELSE 
        RETURN Customer.Balance. 
END.

For the FIND statement in particular, there is another way to do this. When the FIND statement fails, the buffer is left with no record in it. Therefore, you can use the built-in AVAILABLE function to determine if the FIND failed. In this case, we don’t use the information in the ERROR-STATUS system handle, but still use NO-ERROR to prevent the error message from displaying.

METHOD PUBLIC DECIMAL getCustomerBalance(custName AS CHAR): 

    FIND FIRST Customer WHERE Customer.NAME = custName NO-ERROR. 
    IF AVAILABLE Customer THEN 
        RETURN Customer.Balance. 
    ELSE 
        RETURN ERROR. // No Customer found with that name 
END.