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