home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l350 / 3.ddi / EXAMPLES / MSC / TERM.C < prev   
Encoding:
C/C++ Source or Header  |  1993-02-18  |  1.2 KB  |  75 lines

  1. //
  2. // TERM.C -- Sample termination handlers with try-finally
  3. //
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <pharlap.h>
  7. #include <excpt.h>
  8.  
  9. void Level2(void);
  10. void Level3(void);
  11.  
  12. int main()
  13. {
  14.     try
  15.     {
  16.         printf("Hello from main()\n");
  17.         Level2();
  18.     }
  19.     finally
  20.     {
  21.         if (AbnormalTermination())
  22.             printf("Abnormal termination in main()\n");
  23.         else
  24.             printf("Normal termination in main()\n");
  25.     }
  26.  
  27.     printf("Exiting from main()\n");
  28.     return 0;
  29. }
  30.  
  31. void Level2(void)
  32. {
  33.     try
  34.     {
  35.         printf("Hello from Level2()\n");
  36.         Level3();
  37.         printf("Causing exception in Level2() try body\n");
  38.         _asm
  39.         {
  40.             mov    eax,7FFFFFFFh
  41.             mov    ebx,7FFFFFFFh
  42.             add    eax,ebx
  43.             into            ; cause integer overflow
  44.         }
  45.     }
  46.     finally
  47.     {
  48.         if (AbnormalTermination())
  49.             printf("Abnormal termination in Level2()\n");
  50.         else
  51.             printf("Normal termination in Level2()\n");
  52.     }
  53.  
  54.     printf("Exiting from Level2()\n");
  55.     return;
  56. }
  57.  
  58. void Level3(void)
  59. {
  60.     try
  61.     {
  62.         printf("Hello from Level3()\n");
  63.     }
  64.     finally
  65.     {
  66.         if (AbnormalTermination())
  67.             printf("Abnormal termination in Level3()\n");
  68.         else
  69.             printf("Normal termination in Level3()\n");
  70.     }
  71.  
  72.     printf("Exiting from Level3()\n");
  73.     return;
  74. }
  75.