Disabling exceptions in VC++ .NET 2003 while using STL

Started by
1 comment, last by i1977 19 years, 11 months ago
I am using Visual C++ .NET 2003. I wanted to see if disabling exceptions would have any effect on a program''s performance. Just to do a quick test before potentially breaking my real project , I created a new Win32 project with some STL stuff in it, opened its Properties page and in the "Code generation" section, changed "Enable C++ exceptions" to "No" and tried to compile. This resulted in lots of errors while compiling STL stuff. Looking at the header files, I found out that _HAS_EXCEPTIONS needs to be defined to 0 to tell STL not to use exceptions, so I added #define _HAS_EXCEPTIONS 0 to the top of my StdAfx.h. Most errors went away but I was left with "error C2504: ''exception'' : base class undefined" in typeinfo.h. I tried putting _HAS_EXCEPTIONS=0 directly in my project''s "Preprocessor definitions". No change, same error message. So, although I''m sure there is a cleaner solution, I tried defining the "exception" class myself in my StdAfx.h: class exception { }; Now, everything compiles but I get two unresolved externals while linking: Test.obj : error LNK2019: unresolved external symbol "void __cdecl std::_Throw(class std::exception const &)" (?_Throw@std@@YAXABVexception@1@@Z) referenced in function "public: void __thiscall std::exception::_Raise(void)const " (?_Raise@exception@std@@QBEXXZ) Test.obj : error LNK2001: unresolved external symbol "void (__cdecl* std::_Raise_handler)(class std::exception const &)" (?_Raise_handler@std@@3P6AXABVexception@1@@ZA) So, does anyone know what I''m doing wrong? Is there something else I need to do besides defining _HAS_EXCEPTIONS to 0? Surely its possible to use STL and not have exceptions enabled? Thanks for any advice!
Frederic FerlandStrategy First, Inc.http://www.strategyfirst.com
Advertisement
i could be totally wrong but i guess for your #define to work you would need to recompile the STL lib''s?

maybe you could try switching to e.g. SGI''s STL (which comes as a plain bunch of header files), lookup the file "stdexcept" (without the ".h" and go from there.

hope this helps
quote:Surely its possible to use STL and not have exceptions enabled?

So how should push_back() report allocation failure? How should vector::at() signal out-of-bounds conditions?
--God has paid us the intolerable compliment of loving us, in the deepest, most tragic, most inexorable sense.- C.S. Lewis

This topic is closed to new replies.

Advertisement