home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Libraries / HDS 3.02 / Exception / exhandle.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-02-13  |  958 b   |  39 lines  |  [TEXT/MPS ]

  1. /*    A general-purpose exception-handling system for C                    *
  2.  *    by Jonathan Amsterdam, 1991                                            *
  3.  *    BYTE August 1991, p. 259 ff                                            */
  4.  
  5. /* Ver.: 1.1    13.02.93 fpp                                            */
  6.  
  7. #include <setjmp.h>
  8.  
  9. typedef struct {
  10.     int code;                                    /* normal exception code */
  11.     char *buff;                                    /* optional buffer pointer */
  12. } except;
  13.  
  14. typedef struct jbr {
  15.     jmp_buf jb;
  16.     struct jbr *next;
  17.     struct jbr *self;
  18. } jmp_buf_rec;
  19.  
  20. #define WITH_HANDLING    {jmp_buf_rec _jbr; \
  21.                         push_jbr (&_jbr); \
  22.                         if (setjmp(_jbr.jb) == 0) {theException.code = 0; theException.buff = NULL;
  23. #define ON_EXCEPTION    pop_jbr();} else {
  24. #define END_HANDLING    }}
  25.  
  26. #define UNWIND_PROTECT    WITH_HANDLING
  27. #define ON_UNWIND        pop_jbr();}}
  28. #define END_UNWIND        if (theException != 0) reraise();
  29.  
  30. #define EXCEPTION_AND_END    ON_UNWIND
  31.  
  32. extern except theException;
  33.  
  34. void exraise (int ex);
  35. void exraisebuff (except *ex);
  36. void reraise (void);
  37. void push_jbr (jmp_buf_rec *jbr);
  38. void pop_jbr (void);
  39.