Try OpenEdge Now
skip to main content
Object-oriented Programming
Programming with Class-based Objects : Raising and handling error conditions : Raising errors within a property : SET accessors raising ERROR
 
SET accessors raising ERROR
A SET accessor runs when you set the value of the property, for example, on the left side of an Assignment (=) statement or when you pass the property as an OUTPUT parameter. When a SET accessor raises ERROR, it can produce a different result from a property or method raising ERROR on the right side of the assignment.
Thus, after executing the following assignment statement, the iVal variable either changes to the value returned by expression or ERROR is raised on the statement from some problem in expression, in which case iVal remains unchanged at 5:
DEFINE VARIABLE iVal AS INTEGER INITIAL 5 NO-UNDO.iVal = expression.
However, in the following assignment statement, if the SET accessor for the iPropVal property does a RETURN ERROR or an UNDO, THROW, the value of iPropVal will retain its latest value prior to raising ERROR, which can well be the value returned by expression:
CLASS TestReturn:
  DEFINE PROPERTY iPropVal AS INTEGER INITIAL 5 NO-UNDO
    SET ... .
    iPropVal = expression.
END CLASS.
The actual value retained by iPropVal if its SET accessor raises ERROR depends on how you code the SET accessor.
Note: If a property appears on the left side of an assignment and the right side of the assignment raises ERROR, the SET accessor of the left-side property never runs.
When a property appears on the left side of an assignment and the SET accessor raises ERROR, the property can retain its latest value prior to raising ERROR depending on NO-UNDO settings, the property default memory, and any other data that the SET accessor changes. This is no different than any method that raises ERROR, except that the method (SET accessor) is executing on the left side of the assignment, independent of any right-side result.
In a similar fashion, when you pass a property as a routine OUTPUT parameter, if the property SET accessor raises ERROR, and depending on NO-UNDO settings, the SET accessor can leave all data that it affects at their latest values prior to raising ERROR.