views:

243

answers:

4

Hi,

I've recently implemented some vectored exception handling to catch errors in our software. This is especially useful as we've just converted from vc6 to vs2005. We're encountering a few problems with the use of the STL library (generally people doing things they shouldn't). I'm trying to catch these errors with my vectored exception handler.

However this doesn't seem to get called, instead these errors are internally processed by the Microsoft Visual Studio C Runtime library.

My question is;

Is there a way to turn off the runtime error checking and get the exceptions passed to the VE handler?

Thanks Rich

A: 

You can turn off the additional run-time checks. However, not all errors this catches will result in a crash which you can intercept.

On a sidenote: These checks often consume significant performance and are, by default, not turned off in release builds.

sbi
Thanks for the response, could you please give me an idea of how to turn them off, is it a visual studio setting?
Rich
@Rich: I could, but you have already found it -- plus some more than I knew. `:)`
sbi
A: 

#define _SECURE_SCL 0

It's best to do this via project settings, as you could get nasty linker problems if the setting differs within or between files.

MSalters
+1  A: 

http://msdn.microsoft.com/en-us/library/aa985973%28VS.80%29.aspx

#define _SECURE_SCL 1
#define _SECURE_SCL_THROWS 1

The above allows me to throw exceptions.

Rich
Again: Keep in mind that, by default, `_SECURE_SCL` is defined to `1` even in release builds. In some applications this considerably costs performance. You might want to explicitly turn this off in release builds.
sbi
A: 

I ran into this problem a while ago and it took me some time to wrap my head around what they are doing in their runtime. I would recommend reading "Migrating from Previous Versions of Visual C++" on MSDN at least twice. Then read "Extensions to the C Library, Part I: Bounds-checking interfaces (ISO/IEC TR 24731-1)". The latter is the standard that most of the parameter checking stuff is based on.

Once you understand what they are up to, just define _CRT_SECURE_NO_DEPRECATE, _SECURE_SCL, and _SECURE_SCL_THROWS in your project settings. Then make sure that you have "Enable C++ Exceptions" set to "Yes with SEH Exceptions (/EHa)" and "Basic Runtime Checks" set to "Default" in your project. At least, that is what is working for us right now. It did take some time to remove the incorrect code that we had created under VC6 though.

The most important thing that you can do is set aside a few weeks and really dig into what the various options and macros do. Then figure out what works with your code. We didn't do this early enough and it hurt a lot once we had some "bad builds" make it out of engineering.

D.Shawley