开发者

Object Reference Error - Show class name with error?

When I get an Object Ref error, it can sometimes be a real pain to find out which variable is causing the error (when you can't debug). Is there a way for this error to throw the classname that isn't assigned?

So开发者_如何学Go: I want the name of the type of the variable that was unexpectedly null.

Thanks in advance.


I dont think you can get the class name, the closes I get is to get the class and method name, then the stack trace:

try
    {

    }
    catch ( Exception ex )
    {
        xxx.API.ErrorHandler.Handler.HandleError( ex, System.Reflection.MethodBase.GetCurrentMethod().Name, System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName );
    }


Well, its only the information in the stack trace which would be the first step in finding out where the error has originated. Also you should make sure you check the complete stack trace (all inner exceptions too). This would give you the method name with complete namespace. So that should be fairly good step to see where the error is, unless the standard coding is really bad.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜