[英]When Does Visual Studio 6 Catch Structured Exceptions?
This is mostly curiosity, but I've been reading about the history of Visual Studio catching SEH exceptions in a C++ try-catch
construct. 这主要是出于好奇,但是我一直在阅读有关Visual Studio在C ++ try-catch
构造中捕获SEH异常的历史。 I keep running across the assertion that older versions Visual Studio with the /GX flag enabled would "somtimes" catch structured Win32 exceptions in a C++ catch
block. 我一直在断言,启用了/ GX标志的旧版本Visual Studio将“ somtimes”捕获C ++ catch
块中的结构化Win32异常。
Under what circumstances will Visual Studio 6.0 enter the catch block in the following code when built with the /GX flag? 在什么情况下,使用/ GX标志构建时,Visual Studio 6.0将在以下代码中输入catch块吗?
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. 在我自己使用Visual Studio 6 + SP6进行的简单测试中,程序由于未处理的异常而暂停执行,并且从不打印“ In catch”。 However, some articles (like this one) lead me to believe that it's possible to enter the catch
block. 但是,有些文章(像这样的文章)使我相信可以进入catch
块。
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 : 我也猜到了,即使您知道为什么处理此类异常也不好,但对于来到这里的Google员工,请阅读:
http://members.cox.net/doug_web/eh.htm#Q1 http://members.cox.net/doug_web/eh.htm#Q1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.