C++ program capturing information after crash

Hi,

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.
What can make your program crash?

An internal or external error?

On which operating system are you working?

Best regards,

http://ncomputers.org
Last edited on
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.

Rgds

Ri
Check this out:
http://www.cplusplus.com/reference/csignal/signal/
http://en.cppreference.com/w/cpp/utility/program/signal
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>
#include <csignal>

void signal_handler(int)
{
    std::cerr << "Segfault";
    std::abort();
}

int main()
{
    std::signal(SIGSEGV, signal_handler);
    *((int*)0) = 10;
}
Segfault
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.
Last edited on
Topic archived. No new replies allowed.