unhandled exeption with try and catch even..

right now im learning about exception handling using visual c++ express.

this code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <iostream>
using namespace std;

const int DefaultSize = 10;

int main()
{
   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 << "something has gone wrong!" << endl;
   }

   cout << "Done." << endl;
   return 0;
}



is producing the same unhandled exception error as this code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
using namespace std;

const int DefaultSize = 10;

int main()
{
   int top = 90;
   int bottom = 0;
   
   cout << "top / 2 = " << (top/ 2) << endl;

   cout << "top divided by bottom = ";
   cout << (top / bottom) << endl;

   cout << "top / 3 = " << (top/ 3) << endl;

   cout << "Done." << endl;
   return 0;
}



this code is from my book. so it should work. i really don't know what to think about this so anyone know why this is happening?

i even tried a different ide and compiler, same problem.
You need to setup your project configuration correctly for C++ Structured Exception Handling"
ok well i figured it out.
thanks to you actually.

even tho it kinda was configured.

visual studios had the option

"enable C++ exceptions"
the choices were

no, yes, yes with seh exeptions.

it was on yes, which i guess means if theres an exeption.. don't do a damn thing.
so i put it on yes with seh... and it works.

ill look up the difference between those options l8r.

thanks.

Yeah, it's all somewhat messy
what do you mean?
I think MS did their own version of modified version of C++ exception handling,
so it is a bit hit and miss trying to get it right.
closed account (z05DSL3A)
Structured Exception Handling (SEH), is part of the Windows system. To use SEH from C/C++ you use the __try and __except keywords. As the divide by zero is a hardware exception it will be passed up to Windows, who in-turn raises an SEH exception that is not handled by your code unless you map SEH into the C++ exception mechanism (yes with SEH exceptions).

Ah, that clears that up for me.
Exceptions is something that I hardly use.
oh, thank you Grey Wolf.
thanks you to Null for the link. gonna look at it now.
Topic archived. No new replies allowed.