Epilogs
The epilog, an optional unit of code, is always executed before the method is exited, regardless of whether the method terminates normally or is terminated abnormally as a result of an exception (excluding fatal system terminations, power failures, and so on, that leave the JADE runtime environment inoperable).
Use a method epilog in situations where resources must be relinquished or the state of various objects must be restored to some stable state before the method is exited; for example, when closing files, deleting transient objects, or restoring the cursor from an hourglass to a normal pointer.
You can also use epilogs for the normal processing of a method. For example, use an epilog for cleanup logic so that a method does not contain a number of return instructions with the same cleanup logic repeated before each return instruction; that is, your cleanup logic would appear in only the epilog.
When using an epilog to delete an objects, it is not necessary to test for non-null object references before calling the delete instruction.
Define an optional method epilog after the normal method body. As the epilog block has the same scope as the method to which it is attached, it has access to the parameters, constants, and local variables of the method, and to properties and methods of the receiver (self).
There are no restrictions on the kinds of instructions or expressions that may be used in the epilog.
The following example shows the use of the epilog in a print method.
begin [method body] epilog delete tempArray; app.printer.close; form.unloadForm; end;
If both the method body and the epilog contain return instructions that each return a different value, the value returned by the epilog takes precedence, as it is the last value returned.
If an exception occurs while an epilog is being executed, the execution of the entire epilog cannot be guaranteed; the remainder of the epilog may be aborted or resumed, depending on how the exception is handled. Because of this, you should restrict your epilog logic to actions that are unlikely to result in an exception.