setjmp

#include <setjmp.h>
#include <stdio.h>

jmp_buf j;

void raise_exception(void)
{
printf("exception raised\n");
longjmp(j, 3); /* jump to exception handler case 3 */
printf("this line should never appear\n");
}

int main(void)
{
switch (setjmp(j)) {
case 0:
printf("''setjmp'' is initializing ''j''\n");
raise_exception();
printf("this line should never appear\n");
case 1:
printf("Case 1\n");break;
case 2:
printf("Case 2\n");break;
case 3:
printf("Case 3\n");break;
default:
break;
}
return 0;
}

posted on 2019-07-17 22:55  与非朋仔  阅读(108)  评论(0编辑  收藏  举报

导航