#include #include #include "exception.h" #include "memory.h" #define K 1024 #define MEGA (K*K) DEFINE_EXCEPTION(e1); DEFINE_EXCEPTION(e2); static void loop(); static void f1(int); static void loop(void) { int i = 0; for(;;) { printf("loop : %d\n", i); HANDLE(e1, f1(i)); if (EXCEPTION_RAISED(any)) { printf("[HANDLE] Exception \"%s\" received in loop\n", exception_current_name()); printf("[HANDLE] Exception e1 received in loop\n"); } i++; } } static void f1(int i) { switch (i) { case 0: case 2: return; case 1: RAISE(e1, "i == 1 in f1"); case 3: RAISE(e2, "i == 3 in f1"); } } int main(void) { HANDLE(any, loop()); if (EXCEPTION_RAISED(e1)) printf("[HANDLE(any)] Exception e1 received in main\n"); else if (EXCEPTION_RAISED(e2)) printf("[HANDLE(any)] Exception e1 received in main\n"); if (EXCEPTION_RAISED(any)) printf("[HANDLE(any)] Exception \"%s\" received in main (%s)\n", exception_current_name(), (char *) exception_current_parameter()); RAISE(error, NULL); return EXIT_SUCCESS; }