I understood that catch (...) was supposed to catch any exception. In the following program, however, catch (...) fails to catch a floating point (divide by zero) exception.
using namespace std;
int main ()
int top = 90;
int bottom = 0;
cout << "top / 2 = " << top / 2 << endl;
cout << "top / bottom = " << top / bottom << endl;
catch ( ... )
cout << "We have a problem." << endl;
cout << "Done" << endl;
Has the C++ specification changed, or is something wrong with the program?
Thank you very much,
If you're using Visual Studio there is s build option to turn on/off floating point exceptions Configuration Properties\C/C++\Code Generation which will at least get it to throw ( adds /fp:except to comand line ). Exactly what you'd have to catch I'm not sure but
catch(...) should work. As Victor indicates though it's not standard so not portable.
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)