2024-06-18 19:37:43 +08:00
|
|
|
|
|
|
|
|
|
|
|
#ifndef exception_h__
|
|
|
|
#define exception_h__
|
|
|
|
|
|
|
|
#include "setjmp.h"
|
2025-06-24 17:59:23 +08:00
|
|
|
#include "stdlib.h"
|
|
|
|
// #include "mystdlib.h"
|
2024-06-18 19:37:43 +08:00
|
|
|
|
|
|
|
#define THROW_LOG__MAX_SIZE 1024
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct _jmp_fram{
|
|
|
|
struct _jmp_fram *next;
|
|
|
|
struct _jmp_fram *last;
|
2025-06-24 17:59:23 +08:00
|
|
|
// map_def *mem;
|
2024-06-18 19:37:43 +08:00
|
|
|
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;\
|
2025-06-24 17:59:23 +08:00
|
|
|
/*if(l){\
|
2024-06-18 19:37:43 +08:00
|
|
|
__mem_mov(&(l)->mem,&(*j)->mem);\
|
2025-06-24 17:59:23 +08:00
|
|
|
}*/\
|
2024-06-18 19:37:43 +08:00
|
|
|
free(*j);\
|
|
|
|
(*j)=l;\
|
|
|
|
if(*j){\
|
|
|
|
(*j)->next=0;\
|
|
|
|
}\
|
|
|
|
}\
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#define jmp_clear(j) {\
|
|
|
|
if((*j)){\
|
|
|
|
jmp_fram *l=(*j)->last;\
|
2025-06-24 17:59:23 +08:00
|
|
|
/*__mem_clear(&(*j)->mem);*/\
|
2024-06-18 19:37:43 +08:00
|
|
|
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
|
|
|
|
|