I am writing a C++ program that does various sequential stand alone tasks for a certain event. All the tasks are very modular and do not have any dependencies on other tasks.
During the execution of my program, if the program crashes, I want to capture the work I have already done and on restart start from the point of crash since my previous tasks are complete.
I tried doing this by creating an object on stack and capturing the state of my program in it's destructor, but looks like the destructor does not get called after a crash.
I could write the state of the task (ie. success or fail) on entry and exit of the task to a database table or file but don't want to take that overhead.
I could do this by using set_terminate but the function pointer to this call does not take any argument, so I am not sure If I will be able to pass any useful info an record it.
Is there anyway/any known techniques I can do this apart from the above techniques?
I have to wonder why your program is crashing, programs shouldn't crash.
You could use exceptions and possibly get your program able to know what went wrong. On the other hand, if your program could do a hard crash at any point, then there really isn't much more you can do than write everything to a file as it happens.
The tasks I mentioned in my original mail can be wrapped in dll's written by other people. So it can have code that causes it to crash.
I have handled most of them using proper try..catch block.
I am trying to handle crashes caused by Access Violation or memory issues. My platform is Windows Server 2003.
Please note that technically behavior of the program I posted is undefined. Read provided reference to figure out what you can actually do with signals.