#ifndef EXCEPTION_H #define EXCEPTION_H #include #define EXCEPTION_NAME(_E_) exception_name_##_E_ typedef struct exception *exception; extern void exception_pop( exception); extern void exception_push( exception); extern int exception_search( exception); extern void *exception_jmp_buf( exception); extern void exception_uncaught( exception, char*, char*, int); extern int exception_raised(void); extern unsigned char exception_flag; extern exception exception_last_raised; #define DEFINE_EXCEPTION(_E_) \ exception EXCEPTION_NAME(_E_)=(exception)&EXCEPTION_NAME(_E_) #define USE_EXCEPTION(_E_) extern exception EXCEPTION_NAME(_E_) #define HANDLE(_E_,_EXP_) \ (exception_push(EXCEPTION_NAME(_E_)), \ setjmp(exception_jmp_buf(EXCEPTION_NAME(_E_)))==0 \ ? ((_EXP_),(exception_flag=0)) : \ (exception_flag=1 ), \ exception_pop(EXCEPTION_NAME(_E_))) #define RAISE(_E_) \ (exception_last_raised =EXCEPTION_NAME(_E_), \ (exception_search(EXCEPTION_NAME(_E_)) \ ? longjmp(exception_jmp_buf(EXCEPTION_NAME(_E_)),1) \ : exception_uncaught(EXCEPTION_NAME(_E_), #_E_, __FILE__, __LINE__))) #define ECHECK(_E_) \ (EXCEPTION_NAME(_E_) == exception_last_raised) #define RERAISE_IT \ (exception_search(exception_last_raised) \ ? longjmp(exception_jmp_buf(exception_last_raised),1) \ : exception_uncaught(exception_last_raised,"unimplemented basename", __FILE__, __LINE__)) #endif USE_EXCEPTION(any);