猛跑小猪
读它并哭泣!我想到了。如果你不从处理程序中抛出,处理程序将继续,异常也将继续。当你抛出自己的异常并处理它时,魔法就会发生。#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");}