#ifndef exception_h__ #define exception_h__ #include "setjmp.h" #include "stdlib.h" // #include "mystdlib.h" #define THROW_LOG__MAX_SIZE 1024 typedef struct _jmp_fram{ struct _jmp_fram *next; struct _jmp_fram *last; // map_def *mem; jmp_buf fram; }jmp_fram; typedef struct{ size_t jmp_num; jmp_fram *jmp_head; int ret; char *file; int line; char log[THROW_LOG__MAX_SIZE]; }exception_def; #define jmp_next(j) {\ if((*j)){\ (*j)->next=calloc(sizeof(jmp_fram),1);\ (*j)->next->last=(*j);\ (*j)=(*j)->next;\ }else{\ (*j)=calloc(sizeof(jmp_fram),1);\ }\ } #define jmp_last(j) {\ if((*j)){\ jmp_fram *l=(*j)->last;\ /*if(l){\ __mem_mov(&(l)->mem,&(*j)->mem);\ }*/\ free(*j);\ (*j)=l;\ if(*j){\ (*j)->next=0;\ }\ }\ } #define jmp_clear(j) {\ if((*j)){\ jmp_fram *l=(*j)->last;\ /*__mem_clear(&(*j)->mem);*/\ free(*j);\ (*j)=l;\ if(*j){\ (*j)->next=0;\ }\ }\ } #define __try(){\ exception_def *f=exception();\ jmp_fram **h=&f->jmp_head;\ int ret;\ jmp_next(h);\ ret= setjmp(((*h)->fram));\ if(ret){\ jmp_clear(h);\ }\ f->ret=ret;\ } #define try_ __try();if(exception()->ret==0){ #define catch_ {\ exception_def *f=exception();\ jmp_fram **h=&f->jmp_head;\ jmp_last(h);\ }}else #define throw_(fmt,...) __throw(__FILE__,__LINE__,fmt,##__VA_ARGS__) exception_def *exception(); void __throw(char *file,int line,const char *fmt,...); int test_add(int a,int b); #endif