Advertisement
andruhovski

SP-0302 (SEH Demo)

Feb 3rd, 2014
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.76 KB | None | 0 0
  1. // SP0302demo.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. LONG filter1(DWORD ex);
  6. int count=0;
  7. const int max_count=3;
  8. int _tmain(int argc, _TCHAR* argv[])
  9. {
  10.     FILE *fin;
  11.     errno_t err;
  12.     int a=0,b=0,y=0;
  13.     err=fopen_s(&fin,"D:\\A.TXT","rt");
  14.     fscanf_s(fin,"%d\n",&a);
  15.     printf_s("a=%d",a);
  16.     fscanf_s(fin,"%d\n",&b);
  17.     printf_s("b=%d",b);
  18.     __try {
  19.         y=a/(a+b);
  20.     }
  21.     __except(filter1(GetExceptionCode()))
  22.     {
  23.         b=-b;
  24.         y=(a+b)/a;
  25.     }
  26.  
  27.     printf_s("y=%d\n",y);
  28.     getchar();
  29.     return 0;
  30. }
  31.  
  32. LONG filter1(DWORD ex)
  33. {
  34.     if (ex== EXCEPTION_INT_DIVIDE_BY_ZERO)
  35.         if (++count>max_count)
  36.             return EXCEPTION_EXECUTE_HANDLER;
  37.         else
  38.             printf("\n******** %d ********\n",count);
  39.     return EXCEPTION_CONTINUE_EXECUTION;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement