1 #include <stdlib.h> 2 #include <stdio.h> 3 #include <setjmp.h> 4 5 //异常抛错检测 6 jmp_buf buf1; 7 8 double devide(double num1,double num2) 9 { 10 if (num2 == 0) 11 { 12 //跳转到异常处 13 longjmp(buf1, 1); 14 } 15 else 16 { 17 printf("res=%f", num1 / num2); 18 } 19 } 20 21 void main() 22 { 23 //异常处理 24 if (setjmp(buf1) == 1) 25 { 26 printf("除数不能为0 "); 27 return; 28 } 29 30 devide(9, 0); 31 system("pause"); 32 }