libexcept
Limitations

Although it is possible to get a fairly functional exceptions framework using standard ANSI C, there are limitations to the system. This page documents things that cannot be done with libexcept.

Breaking out of an exception block

It is not possible to break out of an exception block using continue, break, return or goto. libexcept has built-in guards that detect when this is done. The following example demonstrates illegal usage:

void illegal(void)
{
int i;
for (i=0; i<10; ++i) {
except_try {
/* Illegal: cannot use break to exit out of an exception block */
break;
/* Illegal: cannot use continue to exit out of an exception block */
continue;
/* Illegal: cannot return from within an exception block */
return;
/* Illegal: do not use goto to break out of an exception block */
goto label;
} except_end
label:
}
}

However, the following is legal:

void legal(void)
{
int i;
except_try {
for (i=0; i<10; ++i) {
/* Legal: Can use break to exit a loop within an exception block */
break;
/* Legal: Can use continue within an exception block */
continue;
/* Legal: Can use goto to jump within an exception block */
goto label;
}
label:
} except_end
}

Note: the same limitations also apply within catch and finally blocks.

Nested exception blocks

It is not possible to have an exception block within another exception block. The following is illegal:

void illegal(void)
{
except_try {
except_try {
printf("hello, world\n");
} except_catch (CircleException, e) {
printf("Circle Exception caught!\n");
}
} except_catch (SquareException, e) {
printf("Square Exception caught!\n");
}
}

However, the following is legal:

void legal_2(void)
{
except_try {
printf("hello, world\n");
} except_catch (CircleException, e) {
printf("Circle Exception caught!\n");
}
}
void legal_1(void)
{
except_try {
legal_2();
} except_catch (SquareException, e) {
printf("Square Exception caught!\n");
}
}