views:

974

answers:

4

Does anybody know how to switch off exception handling option in MSVC? I tried to set the option 'Enable C++ exceptions' to 'NO' and I got warning: warning C4530: C++ exception handler used, but unwind semantics are not enabled. Specify /EHsc

I would like to switch off the exception handler, too, but I don't know how.

In my application I basically need more speer than stability, therefore I chose switching off the exception handling. I do not have any try/catch blocks, but I do use STL. When I switch the option 'Enable C++ exceptions' to 'NO' is there any way how to get rid of those warnings?

A: 

Do you still have try/catch block(s) in your code?

The first thing to do when you get stuck is look up the error on MSDN and/or Google for it. That usually helps. This is what MSDN says:

When the /EHsc option has not been enabled, an object with automatic storage in the frame, between the function doing the throw and the function catching the throw, will not be destroyed. However, an object with automatic storage created in a try or catch block will be destroyed. [...]

dirkgently
A: 

Switching off exceptions is quite hard, as you're dealing with C++ here. It's really in the same category as switching off NULL pointers - how are you going to handle memory allocation failure, for instance?

That said, /EH specifies which exception handling model you want, and "none" is not an option. You can pick /EHa, /EHs, /EHac and /EHsc - [a]ynchronous with or without support for throwing extern "C" functions.

MSalters
A: 

That warning means that you told the compiler you're not going to use exceptions yet you have a try {} catch() {} block in the code. It informs you that although you have that block, if an exception is thrown no desctructors are going to be executed. Turning exceptions off means exactly that - the compiler doesn't produce code for automatic destruction when the stack is unwound in the event of an exceptions.

shoosh
Well, I searched the code, but I don't have any try/catch blocks there. Yet, I create some classes using 'new', does it apply to that too?
No. This is a compiler warning, it appears when compiling a single cpp file. The name of the file appears just before the warning. That's the file which contain the offending code. Worst case you can try to selectivly comment out parts of the file to see what causes the warning.
shoosh
+3  A: 

Most likely you're including one or more standard C++ headers that contain try/catch. The most typical case would be <iostream> - you will get this error on a file which consists of a single line that just includes that. Any other stream header will also do, as will locales.

If you look closely at the error message, it should reference two filenames, not one - your file, and the included file with the error. E.g. in my sample case of #include <iostream>, I get this:

except.cpp
C:\Program Files\Microsoft Visual Studio 9.0\VC\INCLUDE\xlocale(342) : warning C4530: C++ exception handler used, but unwind semantics are not enabled. Specify /EHsc
Pavel Minaev
As a side note, I must add that there really isn't such a thing as ANSI/ISO C++ without exceptions - the language spec doesn't even consider "disabling" them, and the entire standard library - including STL - uses exceptions. Even the containers use them, e.g. std::vector::at()
Pavel Minaev