Handle instance constructor errors
- Last Updated: March 30, 2020
- 2 minute read
- OpenEdge
- Version 12.2
- Documentation
Whenever you or the AVM raise the ERROR condition
on a constructor, the AVM raises that ERROR condition
directly in the statement that instantiated the object using the NEW function, NEW statement,
or DYNAMIC-NEW statement. Regardless of where in
the class hierarchy the constructor is running, an ERROR raised
on the constructor terminates object instantiation immediately.
In addition, instead of returning an object reference to an instantiated
object, the ERROR condition causes the NEW function
to return no object reference, leaving any data element set to receive
a value in any NEW or DYNAMIC-NEW statement
unchanged.
Because ERROR raised on a constructor immediately terminates
object instantiation, you cannot handle the ERROR condition
on a corresponding SUPER or THIS-OBJECT statement that
invokes the constructor from within another constructor. (You cannot specify NO-ERROR for
either of these statements, nor can you use a CATCH block
to handle errors raised on them.) You can only handle constructor
errors on the statement that invokes a NEW or DYNAMIC-NEW to
create the object.
Also, when a constructor raises the ERROR condition, along
with terminating any further object instantiation, the AVM invokes
the destructor, in reverse order of instantiation, for each super
class whose constructor has already completed while instantiating
the class hierarchy.
DELETE OBJECT
THIS-OBJECT to abort class instantiation, which sets the returned
object reference to the Unknown value (?). However, Progress Software Corporation recommends
that you use RETURN ERROR or UNDO, THROW to
return ERROR from the constructor, instead, as
this both aborts class instantiation and raises an ERROR condition that
you can handle in the instantiating context.