home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 40 / IOPROG_40.ISO / SOFT / NETFrameworkSDK.exe / comsdk.cab / samples1.exe / smc / error.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-06-23  |  4.4 KB  |  141 lines

  1. /*****************************************************************************/
  2. #ifndef _ERROR_H_
  3. #define _ERROR_H_
  4. /*****************************************************************************/
  5.  
  6. #ifndef TRAP_VIA_SETJMP
  7. #define TRAP_VIA_SETJMP 0
  8. #endif
  9.  
  10. #ifdef  __IL__
  11. #if     TRAP_VIA_SETJMP
  12. #error  Sorry, can not use setjmp() for trapping errors in managed IL; use SEH.
  13. #endif
  14. #endif
  15.  
  16. /*****************************************************************************/
  17. #if TRAP_VIA_SETJMP
  18.  
  19. #include <setjmp.h>
  20.  
  21. struct  errTrapDesc;
  22. typedef errTrapDesc*ErrTrap;
  23. struct  errTrapDesc
  24. {
  25.     ErrTrap         etdPrev;
  26.     jmp_buf         etdJmpBuf;
  27. };
  28.  
  29. #endif
  30. /*****************************************************************************/
  31.  
  32. #ifndef __SMC__
  33.  
  34. #undef  SMC_ERR
  35. #undef  SMC_WR1
  36. #undef  SMC_WRN
  37. #define SMC_ERR(name, lvl, str)  name,
  38. #define SMC_WR1(name, lvl, str)  name, WRNfirstWarn = name,
  39. #define SMC_WRN(name, lvl, str)  name,
  40. enum    errors
  41. {
  42.     #include "errors.h"
  43.  
  44.     WRNafterWarn
  45. };
  46. #undef  SMC_ERR
  47. #undef  SMC_WR1
  48. #undef  SMC_WRN
  49.  
  50. const
  51. unsigned    WRNcountWarn = WRNafterWarn - WRNfirstWarn + 1;
  52.  
  53. extern  const   char *   errorTable[];
  54. extern  const   char *   errorTable[];
  55.  
  56. extern  BYTE            warnDefault[WRNcountWarn];
  57.  
  58. #endif
  59.  
  60. /*****************************************************************************/
  61.  
  62. #ifndef _COMP_H_
  63. #include "comp.h"
  64. #endif
  65.  
  66. /*****************************************************************************/
  67. #if TRAP_VIA_SETJMP
  68. /*****************************************************************************/
  69.  
  70. #ifndef __IL__
  71. //#pragma message("NOTE: using setjmp for error traps")
  72. #endif
  73.  
  74. #define                 setErrorTrap(comp)                                  \
  75.                                                                             \
  76.     errTrapDesc         __trap;                                             \
  77.                                                                             \
  78.     __trap.etdPrev = comp->cmpErrorTraps;                                   \
  79.                      comp->cmpErrorTraps = &__trap;
  80.  
  81. #define                 begErrorTrap                                        \
  82.                                                                             \
  83.                                                                             \
  84.     int  __errc = setjmp(__trap.etdJmpBuf);                                 \
  85.     if  (__errc == 0)
  86.  
  87. #define                 endErrorTrap(comp)                                  \
  88.                                                                             \
  89.         comp->cmpErrorTraps = __trap.etdPrev;
  90.  
  91. #define                 chkErrorTrap(hand) hand
  92. #define                 fltErrorTrap(comp, xcod, xinf)                      \
  93.                                                                             \
  94.     else
  95.  
  96. #define                 hndErrorTrap(comp)                                  \
  97.                                                                             \
  98.         comp->cmpErrorTraps = __trap.etdPrev;
  99.  
  100. inline  void            jmpErrorTrap(Compiler comp)
  101. {
  102.      assert(comp->cmpErrorTraps);
  103.     longjmp(comp->cmpErrorTraps->etdJmpBuf, 1);
  104. }
  105.  
  106. /*****************************************************************************/
  107. #else   // !TRAP_VIA_SETJMP
  108. /*****************************************************************************/
  109.  
  110. #ifndef __IL__
  111. //#pragma message("NOTE: using SEH for error traps")
  112. #endif
  113.  
  114. extern  int             __SMCfilter  (Compiler  comp, int   xcptCode,
  115.                                                       void *xcptInfo);
  116. extern  void            __SMCraiseErr();
  117.  
  118. const   unsigned        SMC_ERROR_CODE = 0x02345678;
  119.  
  120. inline  void            setErrorTrap(Compiler comp){}
  121. #define                 begErrorTrap    __try
  122.  
  123. inline  void            endErrorTrap(Compiler comp){}
  124.  
  125. #define                 chkErrorTrap __except
  126. #define                 fltErrorTrap __SMCfilter
  127.  
  128. inline  void            hndErrorTrap(Compiler comp){}
  129. inline  void            endErrorTrap(){}
  130.  
  131. inline  void            jmpErrorTrap(Compiler comp)
  132. {
  133.     __SMCraiseErr();
  134. }
  135.  
  136. /*****************************************************************************/
  137. #endif  // !TRAP_VIA_SETJMP
  138. /*****************************************************************************/
  139. #endif
  140. /*****************************************************************************/
  141.