because it didn't... when i run it, it appears to me "floating point exception"i am using this command to build it in my centos box:g++ -g -o test test.cppit prints a warningtest.cpp:11: warning: division by zero in `3 / 0'

this is really bugging me out...it only goes to the catch if I throw something

: : No, C++ isn't Java :-): : then why does exist try catch blocks?: please, can you show me a good way to use exceptions?: using classes of exception or not:

They exist for error handling of your own program. In C, the traditional way to do error handling in function is like this:

[code]ErrorCode func (){... return someErrorCode;}[/code]

The problem with the above is that you'll have to return values calculated in the function through pointers. If the error code is passed with an exception instead, the function can use the return value for actual values.

And imagine an operator overloading:

SomeClass operator = (SomeClass& obj);

All the parameters and the return value must be in a fixed pattern. Without exception handling, you wouldn't be able to handle errors from that function.

Even though this is very old, I thought I would reply since none of the existing replies seem to be correct.

The fpu will trigger a hardware exception on divide-by-zero if the exception is unmasked in the fpu control register (see _control87() or _controlfp()). When the exception is raised, Windows turns it into a SEH (Structured Exception Handler)exception, which is compatible with Microsoft C and is caught using the __try .. __except mechanism. C++ exceptions, using try {} .. catch {} are a different mechanism. The catch (...) statement will only catch SEH exceptions if you tell the compiler that you want to do so. In Visual C++ 2010, go to project properties / Configuration Properties / C/C++ / Code Generation / Enable C++ Exceptions and select "Yes with SEH Exceptions (/EHa)". Then, if a floating point exception is generated, it should be caught by the C++ "catch (...)" statement.

Another problem that can cause confusion is that fpu exceptions are not actually generated until the next floating point operation or fwait instruction. In Visual C++ 2010, if you select "Yes /fp:except" for the "Enable Floating Point Exceptions" option, exceptions will be raised immediately after they are triggered.

Even though this is very old, I thought I would reply since none of the existing replies seem to be correct.

The fpu will trigger a hardware exception on divide-by-zero if the exception is unmasked in the fpu control register (see _control87() or _controlfp()). When the exception is raised, Windows turns it into a SEH (Structured Exception Handler)exception, which is compatible with Microsoft C and is caught using the __try .. __except mechanism. C++ exceptions, using try {} .. catch {} are a different mechanism. The catch (...) statement will only catch SEH exceptions if you tell the compiler that you want to do so. In Visual C++ 2010, go to project properties / Configuration Properties / C/C++ / Code Generation / Enable C++ Exceptions and select "Yes with SEH Exceptions (/EHa)". Then, if a floating point exception is generated, it should be caught by the C++ "catch (...)" statement.

Another problem that can cause confusion is that fpu exceptions are not actually generated until the next floating point operation or fwait instruction. In Visual C++ 2010, if you select "Yes /fp:except" for the "Enable Floating Point Exceptions" option, exceptions will be raised immediately after they are triggered.