#include <iostream>
void MyFunc(void);
class Expt
{
public:
Expt(){};
~Expt(){};
const char *ShowReason() const
{return "Expt类异常";}
};
class Demo{
public:
Demo();
~Demo();
};
Demo::Demo()
{cout<<"构造Demo。"<<endl;
}
Demo::~Demo()
{cout<<"析构 Demo。"<<endl;
}
void MyFunc(){
Demo D;
throw Expt;
}
int main ()
{
cout<<"在main函数中。"<<endl;
try
{cout<<"在try块中,调用MyFunc()。"<<endl;
MyFunc();
}
catch (Expt E)
{
cout<<"在catch异常处理程序中。"<<endl;
cout<<"捕获到Expt类型异常:";
cout<<E.ShowReason()<<endl;
}
catch(char*str)
{
cout<<"捕获到其他异常:"<<str<<endl;
}
cout<<"回到main函数。从这里恢复运行。"<<endl;
return 0;
}
报错在这里~!
D:\Program Files\Desktop\新建文件夹\ou.cpp(17) : error C2065: 'cout' : undeclared identifier
D:\Program Files\Desktop\新建文件夹\ou.cpp(17) : error C2297: '<<' : illegal, right operand has type 'char [11]'
D:\Program Files\Desktop\新建文件夹\ou.cpp(17) : error C2065: 'endl' : undeclared identifier
D:\Program Files\Desktop\新建文件夹\ou.cpp(20) : error C2297: '<<' : illegal, right operand has type 'char [12]'
D:\Program Files\Desktop\新建文件夹\ou.cpp(24) : error C2275: 'Expt' : illegal use of this type as an expression
D:\Program Files\Desktop\新建文件夹\ou.cpp(4) : see declaration of 'Expt'
D:\Program Files\Desktop\新建文件夹\ou.cpp(28) : error C2297: '<<' : illegal, right operand has type 'char [15]'
D:\Program Files\Desktop\新建文件夹\ou.cpp(30) : error C2297: '<<' : illegal, right operand has type 'char [26]'
D:\Program Files\Desktop\新建文件夹\ou.cpp(35) : error C2297: '<<' : illegal, right operand has type 'char [24]'
D:\Program Files\Desktop\新建文件夹\ou.cpp(36) : error C2297: '<<' : illegal, right operand has type 'char [21]'
D:\Program Files\Desktop\新建文件夹\ou.cpp(37) : error C2297: '<<' : illegal, right operand has type 'const char *'
D:\Program Files\Desktop\新建文件夹\ou.cpp(41) : error C2297: '<<' : illegal, right operand has type 'char [16]'
D:\Program Files\Desktop\新建文件夹\ou.cpp(43) : error C2297: '<<' : illegal, right operand has type 'char [31]'
using namespace std; throw Expt();