Can you perform critical code prior to return?

I vaguely recall some mechanism for specifying code that is always to be executed prior to return from a method, even if an error occurs – without catching the error. Anyone know what that might be?

http://developer.xojo.com/trycatch ?

or

http://developer.xojo.com/userguide/exception-handling (see Exception)

Create a class and put the code you need in its Destructor. At the top of your method, create an instance of that class in a local variable. When the variable goes out of scope, its Destructor will fire and clean up your method.

I use this technique with semaphores, among others, to make sure the lock is released when the method exits, no matter how it exits.

The Finally keyword specifies code that always runs even if there’s an exception, however it doesn’t guarantee that the code will run before the method returns.