I've been reading through the book Teach Yourself C++ In 21 Days , by Jesse Liberty and came across Exceptions and Errors chapter. The author uses this example:
int top = 10;
int bottom = 0;
try
{
cout << "top divided by bottom = ";
cout << (top / bottom) << endl;
}
catch(...)
{
cout << "something has gone wrong!" << endl;
}
And it works fine for him. The exception gets caught and the output is:
top divided by bottom = something has gone wrong!
I tried it myself and received the following error:
Unhandled exception at 0x0124152d in stuff.exe: 0xC0000094: Integer division by zero.
According to this thread, "Integer divide by zero is not an exception in standard C++." But Visual Studio is obviously throwing an exception here, though not catching it.
I tried defining top
and bottom
as double
, and I received the following output:
top divided by bottom = 1.#INF
So why the try catch
block isn't catching the integer division by zero
exception?