0

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

3
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by Aranarth
0

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

0

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

1

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.

Edited by Aranarth: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.