George2 wrote:
Hello everyone,
I have tested try-catch works with structured exception, to my
surprise. Previously I think we have to use __try and __except.
Any comments? Here is my test code and I am using Visual Studio 2008.
This is not portable. It may work with VS 2008. In general, it makes
little sense to catch an access violation, a signal is much more
interesting since you may actually be able to do something interesting -
like mapping memory to the location or whatever.
There are a whole lot of reasons you may get an accvio or segmentation
fault, very few of which you can continue with anything sensible.
In some cases, a divide by zero or other arithmetic fault may be
interesting to catch. I think that gcc has a way of catching those, you
need to recompile your arithmetic code with some compiler flag.
>
-
#include <iostream>
-
using namespace std;
-
int main()
-
{
-
int* address = NULL;
-
try{
-
(*address) = 1024;
-
} catch (...)
-
{
-
cout << "access violation caught" << endl;
-
}
-
return 0;
-
}
-
thanks in advance,
George