Visual Studio 6 何时捕获结构化异常?

发布于 2024-09-11 07:16:09 字数 594 浏览 3 评论 0原文

这主要是出于好奇,但我一直在阅读有关 Visual Studio 在 C++ try-catch 构造中捕获 SEH 异常的历史。我一直在断言启用了 /GX 标志的旧版本 Visual Studio 会“有时”在 C++ catch 块中捕获结构化 Win32 异常。

在使用 /GX 标志构建时,Visual Studio 6.0 在什么情况下会在以下代码中输入 catch 块?

char * p = NULL;

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

在我自己使用 Visual Studio 6 + SP6 进行的简单测试中,程序执行因未处理的异常而停止,并且“ In catch”永远不会被打印。但是,有些文章(例如这篇)导致我相信可以进入 catch 块。

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 versions 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

陪你到最终 2024-09-18 07:16:09
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;
}

这也许是我通过网络找到的唯一方法。

据我猜测,即使您知道为什么处理此类异常不好,但对于来这里的谷歌人来说,请阅读:

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文