传智扫地僧课程学习笔记。
#include "iostream"
using namespace std;
class test
{
public:
test( int a = 0,int b = 0)
{
this->a = a;
this->b = b;
cout<<"构造函数"<<endl;
}
~test()
{
cout<<"析构函数"<<endl;
}
protected:
private:
int a;
int b;
};
void mydivide()
{
test t1( 1, 2), t2( 3, 4);
cout<<"mydivide ...要发生异常"<<endl;
throw 1;
}
void main()
{
try
{
mydivide();
}
catch( int a)
{
cout<<"int "<<endl;
}
catch( ... )
{
cout<<"unknow "<<endl;
}
system("pause");
}
/*
运行结果:
构造函数
构造函数
mydivide ...要发生异常
析构函数
析构函数
int
*/