#include<iostream>
#include<cstdlib>
using namespace std;
class stu
{
public:
int b;
stu()
{
b = 12;
}
};
//void fun(int a)
//{
// if (0==a)
// {
// abort();
// }
// cout << "zhengque\n";
//}
void fun2(stu& c)
{
while (c.b< 10)
{
if (5 == c.b)
{
throw c;//可以是'a',123.123浮点数等,只要catch有对应的类型即可。
}
c.b++;
//cout << a << endl;
}
cout << "zhengque\n";
}
void fun1(int a)
{
while (a < 10)
{
if (5 == a)
{
throw a;//可以是'a',123.123浮点数等,只要catch有对应的类型即可。
}
a++;
//cout << a << endl;
}
cout << "zhengque\n";
}
int main()
{
//fun(1);
/*try
{
fun1(3);
}
catch (int b)
{
try
{
fun1(b + 1);
}
catch (int a)
{
}
}
catch (char c)
{
cout << c << endl;
}
catch (...)
{
cout << "default\n";
}*/
stu db;// 抛出对象的时候,要用引用或指针,不然会拷贝备份出来,即拷贝构造函数
try
{
fun2(db);
}
catch (stu& a)
{
}
catch (stu* d)
{
d->b++;
}
system("pause");
return 0;
}