Why is stack unwinding not happening (demo)?
I was hoping to see “exiting” printed, but I’m not getting that,
stack unwinding isn’t happening.
<code>#include<iostream>
#include<cstdio>
using namespace std;
class mytemp
{
std::string theA;
public:
mytemp(const std::string& a)
{
theA = a;
printf("n entering %sn", theA.c_str());
}
~mytemp()
{
printf("n exiting %sn", theA.c_str());
fflush(NULL);
}
};
void C(int x )
{
mytemp obj("==c==");
throw 1;
//cout<<1/0;
}
void B(int y )
{
mytemp obj("==b==");
C(30);
}
void A(int z)
{
mytemp obj("==a==");
B(20);
}
int main()
{
A(10);
return 0;
}
</code>
<code>#include<iostream>
#include<cstdio>
using namespace std;
class mytemp
{
std::string theA;
public:
mytemp(const std::string& a)
{
theA = a;
printf("n entering %sn", theA.c_str());
}
~mytemp()
{
printf("n exiting %sn", theA.c_str());
fflush(NULL);
}
};
void C(int x )
{
mytemp obj("==c==");
throw 1;
//cout<<1/0;
}
void B(int y )
{
mytemp obj("==b==");
C(30);
}
void A(int z)
{
mytemp obj("==a==");
B(20);
}
int main()
{
A(10);
return 0;
}
</code>
#include<iostream>
#include<cstdio>
using namespace std;
class mytemp
{
std::string theA;
public:
mytemp(const std::string& a)
{
theA = a;
printf("n entering %sn", theA.c_str());
}
~mytemp()
{
printf("n exiting %sn", theA.c_str());
fflush(NULL);
}
};
void C(int x )
{
mytemp obj("==c==");
throw 1;
//cout<<1/0;
}
void B(int y )
{
mytemp obj("==b==");
C(30);
}
void A(int z)
{
mytemp obj("==a==");
B(20);
}
int main()
{
A(10);
return 0;
}
7