diff options
author | biouman <biouman> | 2001-05-01 11:27:52 +0000 |
---|---|---|
committer | biouman <biouman> | 2001-05-01 11:27:52 +0000 |
commit | 655f3b2663b9909656b896cf47ad949b4e9644a8 (patch) | |
tree | a9e775e6ea01fbf2140176499d4936a099946e32 /lib/exceptions.c | |
parent | 6b8f02426a4dd9358c7b35d34268db358fd113c3 (diff) |
*** empty log message ***
Diffstat (limited to 'lib/exceptions.c')
-rw-r--r-- | lib/exceptions.c | 35 |
1 files changed, 23 insertions, 12 deletions
diff --git a/lib/exceptions.c b/lib/exceptions.c index 0fc363e..e59013b 100644 --- a/lib/exceptions.c +++ b/lib/exceptions.c @@ -13,6 +13,7 @@ #define _(x) x #endif #include "exceptions.h" +#include "pile.h" char *contexts[128]; int clevel = 0; @@ -23,7 +24,7 @@ char *Estrdup(char *o) if (o) { if (!(r = strdup(o))) { - exception(1, _("Out of memory.")); + exception(2, _("Out of memory.")); } } else { return NULL; @@ -37,7 +38,7 @@ void *Emalloc(size_t s) if (s) { if (!(r = malloc(s))) { - exception(1, _("Out of memory.")); + exception(2, _("Out of memory.")); } } else { return NULL; @@ -48,7 +49,7 @@ void *Emalloc(size_t s) void pushcontext(char *c) { if (clevel == 128) { - exception(1, _("Too much error contexts during pushcontext().")); + exception(2, _("Too much error contexts during pushcontext().")); } contexts[clevel++] = Estrdup(c); #ifdef DEBUG @@ -59,7 +60,7 @@ void pushcontext(char *c) void popcontext(void) { if (clevel == 0) { - exception(1, _("Error context empty, but popcontext() called.")); + exception(2, _("Error context empty, but popcontext() called.")); } free(contexts[--clevel]); } @@ -71,14 +72,24 @@ void flushcontext(void) } } -void exception(int level, char *msg) +/* exception avec level=1 pour une erreur non fatale avec vidage de la pile sinon +pour toutre valeur de level erreur avec terminaison du programme */ + +void exception(int level, char *msg) { int i; - - fprintf(stderr, "Error detected. Showing context.\n"); - for (i = 0; i < clevel; i++) { - fprintf(stderr, " (%i) - %s\n", i, contexts[i]); - } - fprintf(stderr, " Error description: %s\n", msg); - exit(level); + switch (level) { + case 1: + fprintf(stderr, " Error description: %s\n", msg); + flush_pile(); + break; + default: + fprintf(stderr, "Error detected. Showing context.\n"); + for (i = 0; i < clevel; i++) { + fprintf(stderr, " (%i) - %s\n", i, contexts[i]); + } + fprintf(stderr, " Error description: %s\n", msg); + exit(1); + break; + } } |