#include <setjmp.h>
#include <stdio.h>
jmp_buf j;
void raise_exception(void)
{
printf("exception raised
");
longjmp(j, 3); /* jump to exception handler case 3 */
printf("this line should never appear
");
}
int main(void)
{
switch (setjmp(j)) {
case 0:
printf("''setjmp'' is initializing ''j''
");
raise_exception();
printf("this line should never appear
");
case 1:
printf("Case 1
");break;
case 2:
printf("Case 2
");break;
case 3:
printf("Case 3
");break;
default:
break;
}
return 0;
}