且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何捕捉在C语言中的整数除零例外?

更新时间:2023-11-10 14:02:58

被零除导致不确定的行为,没有C语言结构,可以做任何事情。***的办法是零摆在首位,以不分,通过检查分母。

Division by zero leads to undefined behavior, there is no C language construct that can do anything about it. Your best bet is to not divide by zero in the first place, by checking the denominator.

如果你想钓(注意,C有没有例外)这个错误,这将取决于你的编译器和操作系统,你还没有上市。顺便说一句, _control87 只有做浮点运算,并没有做整数运算。

If you want to "catch" (note, C has no exceptions) this error, it will be dependent on your compiler and OS, which you haven't listed. By the way, _control87 has only to do with floating-point operations, and nothing to do with integer operations.