# include <iostream>
using namespace std;
/*
当函数中抛异常的时候,我的局部就会被析构掉
这就叫栈解旋
*/
int divide(int x, int y);
class Person
{
public:
Person()
{
cout << "Person()..." << endl;
}
~Person()
{
cout << "~Person()..." << endl;
}
};
void test01()
{
try
{
divide(10, 0);
}
catch(int e)
{
cout << "异常捕获" << endl;
}
}
int divide(int x, int y)
{
Person p1, p2;
if(y == 0)
{
throw y;
}
return x/y;
}
int main(int argc, char *argv[])
{
test01();
return 0;
}
using namespace std;
/*
当函数中抛异常的时候,我的局部就会被析构掉
这就叫栈解旋
*/
int divide(int x, int y);
class Person
{
public:
Person()
{
cout << "Person()..." << endl;
}
~Person()
{
cout << "~Person()..." << endl;
}
};
void test01()
{
try
{
divide(10, 0);
}
catch(int e)
{
cout << "异常捕获" << endl;
}
}
int divide(int x, int y)
{
Person p1, p2;
if(y == 0)
{
throw y;
}
return x/y;
}
int main(int argc, char *argv[])
{
test01();
return 0;
}