Is there any way to run the code on completion, regardless of what kind of completion (abnormal, normal, uncaught exception, etc.)? I know this is possible in Java, but is it possible in C ++? Im assuming a windows environment.
No - if someone calls TerminateProcess, your process will be destroyed without further adieu and (in particular) without any chance of running another code during the shutdown process.
TerminateProcess
For a normal closing application, I would suggest
atexit()
++ RAII, , , ..
class ShutdownHook { ~ShutdownHook() { // exit handler code } }; int main() { ShutdownHook h; //... }
Object Lifetime Manager ACE. atexit.
atexit
- ; , , , KILL Linux.
, , , , , .