//直接上代码
#include <iostream>
#include <windows.h>
void PrintHelp()
{
printf("Usage:d04 <Number>\n");
}
int main(int argc,char* argv[])
{
int nNumber = 0;
if (argc <2)
{
PrintHelp();
return -1;
}
nNumber = atoi(argv[1]);
__try {
printf("You Entered:%s \n",argv[1]);
if (nNumber<0)
{
__leave;
}
if (nNumber==0)
{
goto EXIT_BYE;
}
if (nNumber>0)
{
return -1;
}
}
__finally {
printf("ret Code:%d\n",AbnormalTermination());
}
EXIT_BYE:
return 0;
}
反汇编之后,
大意就是
在__try保护块中,
VC编译器会在return 及goto之前加入
call MSVCR90!local_unwind4+0x82的函数调用
而local_unwind4又会调用
MSVCR90!NLG_Dispatch2+0x8 (78590adc)
然后又call到
78590adc ffd0 call eax {d04!main+0x10b (0040110b)} ;这里就是__finally终结块代码.
另:
__leave是__try保护块的正常结束.