#include#include jmp_bufjumper; void Func1() { longjmp(jumper,1); } void Func2() { longjmp(jumper,2); } void Func3() { longjmp(jumper,-1); } //错误处理模块 void SetExceptionHandler() { switch ( setjmp(jumper) ) { case 0: //第一次设置,正常 break; case 1: printf( "error 1\n"); break; case 2: printf( "error 2\n"); break; default : printf( "unknown error\n"); break; } } void main( void ) { SetExceptionHandler(); Func1(); Func2(); Func3(); }
输出:
error 1error 2unknown error