1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| int MyExceptionFilter(DWORD exceptionCode, LPEXCEPTION_POINTERS exceptionPointers)
{
fprintf(stderr, "SEH exception of type %08lX! Terminating.\n", exceptionCode);
FILE * logFile = fopen("logfile.txt", "a");
if(logFile != NULL)
{
fprintf(logFile, "SEH exception of type %08lX! Terminating.\n", exceptionCode);
switch(exceptionCode)
{
case EXCEPTION_ACCESS_VIOLATION:
/*Logguer les infos supplémentaires dans exceptionPointers*/
break;
}
fclose(logFile);
}
return EXCEPTION_CONTINUE_SEARCH;
}
int _tmain(int argc, _TCHAR* argv[])
{
__try
{
printf_s("Cette application plante et c'est normal");
double x = 3.1416e-3;
double y = 5;
double *p=NULL;//permet de générer une erreur
for (int n = 0; n < 10; n++)
{
*p= x / y;
y -= 1;
}
return 0;
}
__except(MyExceptionFilter(GetExceptionCode(), GetExceptionInformation())
{
return GetExceptionCode(); /*Ne sera pas exécuté de toute façon*/
}
} |
Partager