In answer to the original question, I have needed to do this in TCL, for example redefining exit to check whether the work has been saved and put up a dialog box if not, before calling out to the original function which gets renamed "tcl_exit". Of course, destructors are a better solution to this problem, but not many languages have those :)