Re: [Dev-C++] Catching illegal pointer access
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Daniel K. O. <dan...@ya...> - 2004-09-19 20:39:22
|
I just forgot to mention, depending on what you want to do, you can use
signals. Obviously signals are used in a very different way than
exceptions, but may be useful if all you want is to dump some
information before the crash. See the example:
----
#include <iostream>
#include <csignal>
#include <cstdlib>
using namespace std;
void foo(int signum)
{
cout << "Program crashed... press enter to finish" << endl;
cin.ignore();
exit(EXIT_FAILURE);
}
int main()
{
signal(SIGSEGV, foo);
int *a = 0;
*a = 1;
return EXIT_SUCCESS;
}
----
But quoting ISO/IEC 9899:1999, page 245:
"An implementation need not generate any of these signals, except as a
result of explicit calls to the raise function. (...) The complete set
of signals, their semantics, and their default handling
is implementation-defined (...)."
Daniel K. O.
|