异常处理
#include<iostream.h>class A
{
public:
void wang()
{
cout<<"AA"<<endl;
}
};
class B:public A
{
public:
void wang()
{
cout<<"BB"<<endl;
}
};
void main()
{
A a;
B b;
try //监测是否异常
{
int age=200;
if(age>100)//判断是否异常
throw a;//有异常时掉出对象a
}
catch(B bb){bb.wang();}
catch(A aa){aa.wang();}//a对象对应的A类的异常处理函数catch
}