http://coolshell.cn/?s=setjmp
http://www.cnblogs.com/hazir/p/c_setjmp_longjmp.html
1 double divide(double to, double by, jmp_buf env) 2 { 3 if(by == 0) 4 if (env) 5 longjmp(env, 1); 6 else 7 return 0; 8 else 9 return to/by; 10 } 11 12 void f() 13 { 14 jmp_buf env; 15 int ret = setjmp(env); 16 printf("jmp: %d\n", ret); 17 if(ret == 0) 18 { 19 printf("result: %lf\n", divide(2.0, 0, env)); 20 } 21 else 22 { 23 printf("error: %d\n", ret); 24 } 25 }
时间: 2024-12-29 23:36:26