views:

99

answers:

1

This is mostly curiosity, but I've been reading about the history of Visual Studio catching SEH exceptions in a C++ try-catch construct. I keep running across the assertion that older version Visual Studio with the /GX flag enabled would "somtimes" catch structured Win32 exceptions in a C++ catch block.

Under what circumstances will Visual Studio 6.0 enter the catch block in the following code when built with the /GX flag?

char * p = NULL;

try
{
    *p = 'A';
}
catch(...)
{
    printf("In catch\n");
}

In my own simple tests with Visual Studio 6 + SP6 program execution halts with an unhanded exception and "In catch" is never printed. However, some articles (like this one) lead me to believe that it's possible to enter the catch block.

A: 
int main()
{
__try
{
int *pInt = NULL;
*pInt = 0;// throw some kind of exception

}
__except( EXCEPTION_EXECUTE_HANDLER )
{
DWORD dw = GetExceptionCode();
switch(dw)
{
case EXCEPTION_ACCESS_VIOLATION:
cout << "access violation\n";
break;
case EXCEPTION_INT_DIVIDE_BY_ZERO:
cout << "int divide by zero\n";
break;
case EXCEPTION_FLT_DIVIDE_BY_ZERO:
cout << "floating point divide by zero\n";
break;
// other cases
}
}

return 0;
} 

Thats Perhaps the only way I found Looking over the net.

Also as I can guess Even you know why it is not good to handle such exceptions, still for googlers coming here, do read :

http://members.cox.net/doug_web/eh.htm#Q1

loxxy
Q2 in the link you provided answers my question exactly. Thanks!
Scott Danahy
loxxy
Yeah, not sure how I missed that link. But, thanks for pointing it out.
Scott Danahy