小编ano*_*mvs的帖子

捕获异常后崩溃

捕获std :: bad_exception后为什么会崩溃?(我正在使用VC7)

#include "stdafx.h"
#include <exception>

int validateInt (int x) throw (int,std::bad_exception) {
    if ( 0 == x ) {
        throw std::bad_exception("x");
    }
    return x;
}

class C {  
    int i;    
public:  
    C(int);  
};  

C::C(int ii)  
try : i( validateInt(ii) ) {  
    std::cout << "I'm in constructor function body\n";
} catch (std::exception& e) {  
    std::cout << "I caught an exception...\n";
}

int _tmain(int argc, _TCHAR* argv[]) {
    C a(0);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

c++ exception

8
推荐指数
1
解决办法
214
查看次数

标签 统计

c++ ×1

exception ×1