Here's the question again:
Suppose you want to make sure that a routine 'clean_up' is executed immediately before your application exits ... maybe this is enough:
class MAIN
creation make
feature
make is
do
...
clean_up
rescue
...
clean_up
end
end
... but it turns out this is not enough - what's the problem?
The problem is this feature from class EXCEPTIONS:
die(code: INTEGER)
-- Terminate execution with exit status 'code',
-- without triggering an exception
If a call is made to die, execution will never reach the end of the creation feature, nor the end of any rescue clause associated with it. Therefore, clean_up will not be executed.
A possible workaround would be to have the root class inherit from MEMORY and redefine destroy so that it calls clean_up. However, this does not work under Visual Eiffel 2.0g (I've not tried it on any other compilers). Although the description of die in the Eiffel Library Standard, Vintage 95 (ELS95) is exactly as quoted above, the common English meaning of die suggests that a reasonable behaviour is to terminate execution immediately, in which case destroy will not be called for the root class. Yet, for destroy to be really useful the user needs to be confident that it will be called no matter what happens.
I think the only solution is a methodological one - "Never Say Die". Or, if you really feel you must call die, do so only from the end of your clean_up routine. Routine die is after all a "goto" by another name.
Eiffel and NICE are registered trademarks of the Nonprofit International Consortium for Eiffel.