首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

C++exception handling(vc2010)解决方案

2012-02-29 
C++exception handling(vc2010)#include stdafx.h#include exception#include iostream#include fs

C++exception handling(vc2010)
#include "stdafx.h"

#include <exception>
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

class A{};
class B{};

void my_t(){
cout<<"i am terminate..."<<endl;
exit(0);
}
void my_u1(){throw A();}
void my_u2(){throw ;}

void t(){
throw B(); \\cannot via 不能通过是怎么回事?是编译器的问题吗?
}
void f() throw(A){t();}
void g() throw(A,bad_exception){t();}

int main(){
set_terminate(my_t);
set_unexpected(my_u1);
try{
f();
}catch(A&){
cout<<"caught an A..."<<endl;
}
set_unexpected(my_u2);
try{g();
}catch(bad_exception&){
cout<<"caught a bad_exception.."<<endl;
}
try{
f();
}catch(...){
cout<<"this will never print"<<endl;
}
}

谢谢

[解决办法]
程序可以编译通过.可能你的编译器问题

[解决办法]
VC2008,CB2010,GCC3.5都可以
我用VC6都可以编译
throw B(); \\cannot via 不能通过是怎么回事?是编译器的问题吗?
不会是\\的问题?
//才是C的注释

[解决办法]
编译器不支持吧
[解决办法]
VS2010编译通过(命令行),可能是项目设置的问题

热点排行