Simple and cross-compiler Structured Exception Handling for C/C++
- seh.h: Exception handler that fully listenning on system signal and custom
- seh_lite.h: Exception handler without listenning on system signal
seh.h:
seh_t seh;
seh_try (seh)
{
int* ptr = NULL;
*ptr = 0; /* Throw exception here */
}
seh_catch (seh_get() == SEH_SEGFAULT)
{
fprintf(stderr, "Segment fault exception has been thrown\n");
}
seh_finally (seh)
{
printf("Finally of try/catch\n");
}
seh_lite.h
seh_lite_t ctx;
seh_lite_try (ctx)
{
printf("prepare to throw an error\n");
seh_lite_throw(1);
printf("should not should this\n");
}
seh_lite_catch (seh_lite_get() == 1)
{
printf("catch an error that threw with value=1.\n");
}
seh_lite_finally (ctx)
{
printf("finally we done.\n");
}