Exceptions not being handled
I decided to read about exceptions finally and the very first example isn't running as expected.
I'm using VC++. This didn't work on dev-c++ either.
Here's the code:
Code:
#include "stdafx.h"
using std::cout;
using std::endl;
int main(int argc, char *argv[])
{
int top = 90;
int bottom = 0;
try
{
cout <<"top /2 = " << (top / 2) << endl;
cout <<"top divided by bottom =";
cout <<(top / bottom)<<endl;
cout <<"top / 3 = " <<(top/3) <<endl;
}
catch(...)
{
cout << "An exception has been thrown." <<endl;
}
cout <<"Done." <<endl;
system("PAUSE");
return EXIT_SUCCESS;
}
Here's whats in the included header
Code:
#pragma once
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#include <stdio.h> //unrelated:why is this needed?
#include <tchar.h> //unrelated:why is this needed?
#include <cstdlib>
#include <iostream>
Here's what happens.
It compiles without a complaint but when I run it without debugging instead of the exception being handled by the catch block, windows send error report appears and none of the code following the catch block gets executed. If I run it with debugging it tells me that there is an unhandled exception of (expectedly) integer divide by zero. shouldn't the catch(...) be handling that exception instead of the program crashing?