How can I declare a separate function which will be called in case of Run-Time Error to prevent program crash ?

Look into "exceptions" (throw and catch). It won't be a magic solution, you have to predict the run time errors. But it is better than nothing.

Dave

I do not agree with you. catch catches only throw statement. It does not catch Integer Divide by Zero or NULL pointer dereferencing conditions.

See
http://www.cplusplus.com/reference/clibrary/csignal/signal/

Note that in the case of a segmentation fault or division by zero all you can do in the signal handlers is to terminate the program in a controlled way, because when the signal handler exits, execution will be continued at the point where the problem occurred, which will most likely result in disaster.

However, under Windows there is structured exception handling, which throws a real exception in the case of segfaults or div by zero. In that case, you could continue execution if you wish. Still, that could be dangerous since things were left unfinished.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.