This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
| Other format: | [Raw text] | |
Output I expected from the program: ----------------------------------- In try block In catch block (1 | TESTMESSAGE) resume---> und wieder im try block
output I got: ------------- In try block In catch block (1 | TESTMESSAGE) resume--->
code: ----- #include <setjmp.h> #include <stdio.h> #include <assert.h>
#define MAXESTACK 100 #define MAXEENV 100 #define FALSE 0 #define TRUE 1
struct exception {
int errNum;
char* errMsg;
jmp_buf resume;
};struct excenv {
jmp_buf excJmp;
struct exception excStack[MAXESTACK];
int excStackInd;
enum Bool_t inCatch;
};static struct excenv excEnv[MAXEENV]; static int excEnvInd = -1;
void NewExcEnv(void) {
excEnv[++excEnvInd].excStackInd = -1;
excEnv[excEnvInd].inCatch = false;
}#define TRY \
NewExcEnv(); \
if(setjmp(excEnv[excEnvInd].excJmp) == 0) {struct exception* CatchExc(void) {
struct excenv* ee = &excEnv[excEnvInd];ee->inCatch = true; return (ee->excStackInd>=0)?&ee->excStack[(ee->excStackInd)--]:0; }
#define CATCH(e) }\
else while(e=CatchExc()) {void DelExcEnv(void) {
excEnvInd--;
}#define ENDTRY excEnv[excEnvInd].inCatch = false; }\ DelExcEnv();
void ThrowExc(int en, const char* const em) {
struct excenv* ee;
int eei = excEnv[excEnvInd].inCatch?excEnvInd-1:excEnvInd;
struct exception* e;ee = &excEnv[eei]; e = &(ee->excStack[++(ee->excStackInd)]);
e->errNum = en; e->errMsg = (char*)calloc(strlen(em)+1, sizeof(char)); strcpy(e->errMsg, em);
if(setjmp(e->resume) == 0)
longjmp(ee->excJmp, 1);
else
puts("resume--->");return; }
void resumeAfterExc(void) {
}#define RESUME(e) excEnv[excEnvInd].inCatch = false; \ longjmp(e->resume, 1); #define FORWARD
int main(void) {
struct exception* e; NewExcEnv();
if(setjmp (excEnv[excEnvInd].excJmp) == 0) {
puts("In try block");
ThrowExc(1, "TESTMESSAGE");
puts("und wieder im try block");
} else
while(e=CatchExc()) {
printf("In catch block (%d | %s)\n", e->errNum, e->errMsg);
excEnv[excEnvInd].inCatch = false;
longjmp(e->resume, 1);
excEnv[excEnvInd].inCatch = false;
}
DelExcEnv();/* TRY
puts("In try block");
THROW(1, "TESTMESSAGE")
puts("und wieder im try block");
CATCH(e)
printf("In catch block (%d | %s)\n", e->errNum, e->errMsg);
RESUME(e)
ENDTRY*/return 0; }
Attachment:
pgp00000.pgp
Description: PGP signature
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |