相关疑难解决方法(0)

MSVC x64中的C++异常"跳过"Try-Catch子句

我正在用C++编写程序.该程序已经适用于Win32(x86),最近我尝试为x64本地编译它.当然,东西不能马上工作.

在调试问题后,我设法使用这个简单的代码片段重现它:

class MyException { };

int main()
{
    try {
        for (;;) {
            try {
                std::cout << "Throwing" << std::endl;

                throw MyException();

                if (1 == 0) {
                    continue;
                }
            } catch (const MyException&) {
                std::cout << "Catch 1" << std::endl;
            }
        }
    } catch (const MyException&) {
        std::cout << "Catch 2" << std::endl;
    }

    std::cout << "Done" << std::endl;

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

(我很快就会解释这if (1==0)条款)

使用MSVC for x86编译此代码时(我使用过2010),结果如预期:

Throwing
Catch 1
Throwing
Catch 1
Throwing
Catch 1
Throwing …
Run Code Online (Sandbox Code Playgroud)

c++ windows 64-bit exception visual-c++

17
推荐指数
1
解决办法
1671
查看次数

标签 统计

64-bit ×1

c++ ×1

exception ×1

visual-c++ ×1

windows ×1