开发者

How to catch NullRefenceException in Visual Studio 2010

I am debuggin a subtle bug that is thrown from a .net custom compone开发者_C百科nt (no source and obfuscated). The component throws a NullReferenceException in its OnPaint() method which makes calls to subscribers, including my code. I am 100% sure that the problem is in my code. The problem is that visual studio debugger does not stop at the point where the exception is thrown, as it should (I enabled NullReferenceException in the Debug/Exceptions dialog).

This is the first time I encountered such a problem in visual studio. Any ideas on identifying offending code, please?

Kemal


Likely the problem is your code isn't throwing the NullReferenceException, however it is probably returning null at some point. You could try adding guard conditions at the end of your functions that ensure you are not returning null, such as an Debug.Assert(retVal != null, "Returned null in function").

If you are sure you own code is throwing a NullReferenceException, make sure you turn on thrown exceptions, rather than user-unhandled ones.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜