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, THROW or BLOCK-LEVEL ON ERROR UNDO, THROW, does not affect the destructor block of a class.
  • Using the UNDO, THROW statement in the CATCH or FINALLY block of a destructor results in a compiler error because UNDO, THROW, in this context, would throw the condition out of the destructor block, which is not allowed. You can, however, use UNDO, THROW in 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 local CATCH block.
  • Using RETURN ERROR in the body of a destructor generates a compiler error.
  • Unhandled STOP conditions normally propagate up by default. However this does not occur if the STOP condition is initiated within the destructor block. Instead, any error message is displayed to the current output device and the condition is cleared.