Why do I get CA1806 when I catch exception in C++/CLI?
- by brickner
I've recently upgraded my project from Visual Studio 2008 to Visual Studio 2010.
By enabling Code Analysis and compiling in Release, I'm getting warning CA1806: Do not ignore method results.
I've managed to reduce the code that produces the warning to this code:
.h file:
public ref class Foo
{
public:
void Bar();
};
.cpp file:
void Foo::Bar()
{
try
{
}
catch (const std::exception&) // here I get the warning
{
}
}
the warning:
CA1806 : Microsoft.Usage :
'Foo::Bar(void)' calls
'Global::__CxxRegisterExceptionObject(void*,
void*)' but does not use the HRESULT
or error code that the method returns.
This could lead to unexpected behavior
in error conditions or low-resource
situations. Use the result in a
conditional statement, assign the
result to a variable, or pass it as an
argument to another method.
If I try to use the exception value or do catch(...) the warning still appears. If I catch managed exceptions instead or compile in Debug I don't get the warning.
Why do I get this warning?
UPDATE
I've decided to open a bug report on Microsoft Connect.