开发者

Why do I get CA1806 when I catch exception in C++/CLI?

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.


This is a Visual Studio 2010 bug.

As you can see in the bug report, Microsoft reproduced the bug and has decided to postpone the resolution with no workaround.

You are welcome to vote for the bug so maybe Microsoft will decide to resolve it sooner.


Could be because you didn't call any code that could throw.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜