|
|

楼主 |
发表于 2007-5-8 13:26:00
|
显示全部楼层
Re: 基础问题:How To catch 0xC0000005 exception?
自问自答吧:
//SEH的错误代码查看过滤方法
int filter(unsigned int code, struct _EXCEPTION_POINTERS *ep) {
if (code == EXCEPTION_ACCESS_VIOLATION) {
//puts("caught AV as expected.");
return EXCEPTION_EXECUTE_HANDLER;
}
else {
//puts("didn't catch AV, unexpected.");
return EXCEPTION_CONTINUE_SEARCH;
};
}
void mydel(Dem *p) {
__try {
delete(p); //野指针重复释放原本会出错,但错误能被处理掉而继续运行
} __except(filter(GetExceptionCode(), GetExceptionInformation()))
{
MessageBox(NULL, "访问野指针,出错!!", NULL, NULL);
}
}
int main()
{
int *p = new int;
int *p1 = p;
delete(p);
p = NULL;
mydel(p1);
...
}
|
|