home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d1xx / d179 / excption.lha / Excption / essai.c < prev    next >
C/C++ Source or Header  |  1989-02-25  |  3KB  |  111 lines

  1. /**************************************************************************/
  2. /*                                                                        */
  3. /*                                                                        */
  4. /*                                                                        */
  5. /*                EXCEPTION EXAMPLE                                       */
  6. /*               ==========================================               */
  7. /*                                                                        */
  8. /*                                                                        */
  9. /*  MODULE      : Exception                                               */
  10. /*  NOM         : essai.c                                                 */
  11. /*  FONCTION    :                                                         */
  12. /*                                                                        */
  13. /*  RESPONSABLE : HEWES Gerald                                            */
  14. /*  TEL         : 33 (1) 46 24 20 27                                      */
  15. /*                                                                        */
  16. /**************************************************************************/
  17.  
  18. /**************************************************************************/
  19. /*                                                                        */
  20. /* HEW 880324 Example file of exception handler                           */
  21. /*                                                                        */
  22. /**************************************************************************/
  23.  
  24.  
  25.  
  26. #include <stdio.h>
  27. #include "local:excption.h"
  28. #include <proto/exec.h>
  29.  
  30. ExcpGlobal;
  31.  
  32. void Subroutine();
  33. void Subroutine2();
  34.  
  35. main()
  36. {
  37.   printf("Hello World! Watch:\n");
  38.  
  39.   MAIN
  40.    {
  41.      printf("protected code\n");
  42.      Subroutine();
  43.      Subroutine2();
  44.      puts("Everything Works Fine To Here\n");
  45.    }
  46.   EXCEPTION
  47.    {
  48.      printf("Handler\n");
  49.      printf("Exception : %d \n",Eclass);
  50.    }
  51.   OUT
  52.  
  53.   puts("Well Exception seems to work! Bye!\n");
  54.   return(0);
  55. }
  56.  
  57. void Subroutine()
  58.  
  59. {
  60.  ExcpDeclare;
  61.  FILE *handle;
  62.  int x=1,z;
  63.  int y = 0;
  64.  
  65.  printf("Still OK\n");
  66.  
  67.  BEGIN
  68.   {
  69.     printf("Before Divide\n");
  70.     z = x/y;
  71.     printf("After Divide\n");
  72.     if (!(handle = fopen("tourt","w"))) RAISE(IO_WRITE_ERROR);
  73.     if (!fprintf(handle,"Hello World!\n")) RAISE(IO_WRITE_ERROR);
  74.     printf("We wrote into the file\n");
  75.   }
  76.  EXCEPTION
  77.   {
  78.    printf("Error Class = %d\n",Eclass);
  79.    if (Eclass == 5) printf("Divide by Zero\n");
  80.    else printf("IO ERROR\n");
  81.   }
  82.  END
  83. }
  84.  
  85. void Subroutine2()
  86.  
  87. {
  88.  int *x,y;
  89.  ExcpDeclare;
  90.  
  91.  
  92.  printf("Still OK\n");
  93.  
  94.  BEGIN
  95.   {
  96.     printf("Before Bad Address\n");
  97.     x = (int *)1023;
  98.     y = *x;
  99.     printf("After Bad Address\n");
  100.   }
  101.  EXCEPTION
  102.   {
  103.    printf("Error Class = %d\n",Eclass);
  104.    if (Eclass == 2) printf("Bus Error\n");
  105.    if (Eclass == 3) printf("Bad Address\n");
  106.    else printf("FATAL ERROR\n");
  107.   }
  108.  END
  109. }
  110.  
  111.