Throw a condition out of a destructor
- Last Updated: January 16, 2024
- 1 minute read
- OpenEdge
- Version 12.8
- Documentation
It is not possible to throw either an ERROR or
STOP condition out of a class destructor. The
destructor of a class can run at unexpected times, at the end of any statement, or at an
END block where variables go out of scope.
Therefore, you would not be able to effectively write code to handle any condition that
was thrown out of the destructor block. Because of this, the AVM forces the condition to
be handled within the block itself. It can be handled in all the usual ways, such as
using an ON phrase (implicit or explicit) or by using a
CATCH block.
Additionally, note that for destructors:
- Using
ROUTINE-LEVEL ON ERROR UNDO, THROWorBLOCK-LEVEL ON ERROR UNDO, THROW, does not affect the destructor block of a class. - Using the
UNDO, THROWstatement in theCATCHorFINALLYblock of a destructor results in a compiler error becauseUNDO, THROW, in this context, would throw the condition out of the destructor block, which is not allowed. You can, however, useUNDO, THROWin the body of the destructor itself. This raises the condition within the context of the block and it can be handled either by default error handling or by a localCATCHblock. - Using
RETURN ERRORin the body of a destructor generates a compiler error. - Unhandled
STOPconditions normally propagate up by default. However this does not occur if theSTOPcondition is initiated within the destructor block. Instead, any error message is displayed to the current output device and the condition is cleared.