I’m trying to catch dividing by zero attempt:
int _tmain(int argc, _TCHAR* argv[])
{
int a = 5;
try
{
int b = a / 0;
}
catch(const exception& e)
{
cerr << e.what();
}
catch(...)
{
cerr << "Unknown error.";
}
cin.get();
return 0;
}
and basically it doesn’t work. Any advice why?
Thank you.
P.S.
Any chance that in the future code can be placed between [code][/code] tags instead of four spaces?
Divide by zero does not raise any exceptions in Standard C++, instead it gives you undefined behaviour. Typically, if you want to raise an exception you need to do it yourself: