有什么办法找出哪些对象引起的NullReferenceException? [英] Is there any way to find out which object caused the NullReferenceException?
本文介绍了有什么办法找出哪些对象引起的NullReferenceException?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法找出导致流入catch块从一个NullReferenceException控制对象的名字,这样我们就可以很容易地通过给予警告或日志记录为空对象调试?
Is there any way to find the object name that caused the control to flow into the catch block from a NullReferenceException, so that we can easily debug by giving an alert or logging the object that was null?
推荐答案
没有。结果
你只得到堆栈跟踪,包括行号。结果
这可以帮助你在简单的情况下是这样的:
No.
You only get the stack trace including line numbers.
This helps you in simple cases like this:
var result = myString.Trim();
但它并不像这样行帮助:
But it doesn't help in lines like this:
var result = myObj.Method1().Method2();
这篇关于有什么办法找出哪些对象引起的NullReferenceException?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文