0

即如果你使用它,它可以触发Object reference not set to an instance of an object

try 
{
  Dictionary<int,int> ZZZ; 
  ZZZ[1]= ..;
}
catch(Exception e)
{    
    var stackTrace = new StackTrace(e);
    var frames = stackTrace.GetFrames();
    var method = frames[0].GetMethod(); 
    Console.WriteLine(method.Name);
}

但是,使用 StackTrace 我们可以获得发生此错误的方法的名称。

但是,我们如何获取触发错误的属性名称呢?在其他语言中,例如php,有办法找到(使用debug_backtrace)上次发生的方法。

有没有类似的,所以它可以发现上次调用了ie set_ZZZ()(autosetter)方法,或者它可以直接说ZZZ属性导致问题?

4

0 回答 0