home *** CD-ROM | disk | FTP | other *** search
- /* A general-purpose exception-handling system for C *
- * by Jonathan Amsterdam, 1991 *
- * BYTE August 1991, p. 259 ff */
-
- /* Ver.: 1.1 13.02.93 fpp */
-
- #include <setjmp.h>
-
- typedef struct {
- int code; /* normal exception code */
- char *buff; /* optional buffer pointer */
- } except;
-
- typedef struct jbr {
- jmp_buf jb;
- struct jbr *next;
- struct jbr *self;
- } jmp_buf_rec;
-
- #define WITH_HANDLING {jmp_buf_rec _jbr; \
- push_jbr (&_jbr); \
- if (setjmp(_jbr.jb) == 0) {theException.code = 0; theException.buff = NULL;
- #define ON_EXCEPTION pop_jbr();} else {
- #define END_HANDLING }}
-
- #define UNWIND_PROTECT WITH_HANDLING
- #define ON_UNWIND pop_jbr();}}
- #define END_UNWIND if (theException != 0) reraise();
-
- #define EXCEPTION_AND_END ON_UNWIND
-
- extern except theException;
-
- void exraise (int ex);
- void exraisebuff (except *ex);
- void reraise (void);
- void push_jbr (jmp_buf_rec *jbr);
- void pop_jbr (void);
-