00001 00008 #ifndef _EXCEPTION_H 00009 #define _EXCEPTION_H 00010 00011 #include <stdlib.h> 00012 #include <stdarg.h> 00013 #include <setjmp.h> 00014 00015 #ifndef __cplusplus 00016 #define TRY { EXCEPTIONHANDLER *_handler = create_exception_handler(); if (_handler==NULL) output_error("%s(%d): exception handler creation failed",__FILE__,__LINE__); else if (setjmp(_handler->buf)==0) { 00017 #define THROW(X) throw_exception(X); 00018 #define CATCH(X) } else {X = exception_msg(); 00019 #define ENDCATCH } delete_exception_handler(_handler);} 00020 #endif 00021 00022 typedef struct s_exception_handler { 00023 int id; 00024 jmp_buf buf; 00025 char msg[1024]; 00026 struct s_exception_handler *next; 00027 } EXCEPTIONHANDLER; 00029 #ifdef __cplusplus 00030 extern "C" { 00031 #endif 00032 00033 EXCEPTIONHANDLER *create_exception_handler(); 00034 void delete_exception_handler(EXCEPTIONHANDLER *ptr); 00035 void throw_exception(char *msg, ...); 00036 char *exception_msg(void); 00037 00038 #ifdef __cplusplus 00039 } 00040 #endif 00041 00042 #endif 00043