异常是哪个函数帧中
class Test
{
public:
Test(){std::cout<<"构造"<<std::endl;}
Test(Test const& obj)
{
std::cout<<"拷贝构造"<<std::endl;
}
~Test(){std::cout<<"析构"<<std::endl;}
public:
void f(int i) throw (Test)
{
if(i==0)
throw Test();
}
void what() const
{
std::cout<<"发生异常"<<std::endl;
}
};
int main()
{
try
{
Test obj;
obj.f(0);
}
catch(Test e) //这里不用引用,说是:obj拷贝一个临时对象,临时对象,然后拷贝生成了e
{
e.what();
}
return 0;
}
f抛出一个对象,Test()在f的函数帧中, 这个Test() 是如何拷贝到
main函数的函数帧呢??
以下是main的部分反汇编代码(有的地方看不懂, 汇编牛牛能帮忙注释以下嘛?)
33: Test obj;
004013E8 lea ecx,[obj]
004013EB call @ILT+165(Test::Test) (004010aa)
004013F0 mov dword ptr [ebp-1Ch],eax //eax将this传给[ebp-1Ch]
004013F3 mov byte ptr [ebp-4],1
34: obj.f(0);
004013F7 push 0 //压入立即数
004013F9 lea ecx,[obj] //_stdcall调用
004013FC call @ILT+155(Test::f) (004010a0)
35: }
00401401 mov byte ptr [ebp-4],0 //[ebp-4]里面保存的是 this,析构的时候放0-----------------这里理解有问题
00401405 lea ecx,[obj] //如果上一条指令的注释是对的话,这里就有问题了,this变成0,如果调用析构呢??
00401408 call @ILT+45(Test::~Test) (00401032)
36: catch(Test e)
0040140D jmp __tryend$_main$1 (0040142d)
__catch$_main$0:
0040140F mov byte ptr [ebp-4],3
37: {
38:
39: e.what();
00401413 lea ecx,[e]
00401416 call @ILT+25(Test::what) (0040101e)
40:
41: }
0040141B mov byte ptr [ebp-4],2
0040141F lea ecx,[e]
00401422 call @ILT+45(Test::~Test) (00401032)
00401427 mov eax,offset __tryend$_main$1 (0040142d)
0040142C ret
42: return 0;
0040142D mov dword ptr [ebp-4],0FFFFFFFFh
00401434 xor eax,eax
43:
44: }
谢谢了啊