捕获访问冲突异常?例int *ptr;*ptr = 1000;我可以使用标准C ++捕获内存访问冲突异常,而无需使用任何特定的Microsoft。
3 回答
猛跑小猪
TA贡献1858条经验 获得超8个赞
读它并哭泣!
我想到了。如果你不从处理程序中抛出,处理程序将继续,异常也将继续。
当你抛出自己的异常并处理它时,魔法就会发生。
#include "stdafx.h"#include <stdio.h>#include <stdlib.h>#include <signal.h>#include <tchar.h>void SignalHandler(int signal){
printf("Signal %d",signal);
throw "!Access Violation!";}int main(){
typedef void (*SignalHandlerPointer)(int);
SignalHandlerPointer previousHandler;
previousHandler = signal(SIGSEGV , SignalHandler);
try{
*(int *) 0 = 0;// Baaaaaaad thing that should never be caught. You should write good code in the first place.
}
catch(char *e)
{
printf("Exception Caught: %s\n",e);
}
printf("Now we continue, unhindered, like the abomination never happened. (I am an EVIL genius)\n");
printf("But please kids, DONT TRY THIS AT HOME ;)\n");}- 3 回答
- 0 关注
- 731 浏览
添加回答
举报
0/150
提交
取消
