C++ : Catch a divide by zero error
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Here is a simple piece of code where a division by zero occurs. I'm trying to catch it : #include <iostream> int main(int argc, char *argv[]) { int Dividend = 10; int Divisor = 0; try { std::cout << Dividend / Divisor; } catch(...) { std::cout << "Error."; } return 0; } But the application crashes anyway (even though I put the option -fexceptions of MinGW ). Is it possible to catch such an exception (which I understand is not a C++ exception, but a FPU exception) ? I'm aware that I could check for the divisor before dividing, but I made the