C#:捕获异常会引发异常

时间:2018-01-30 11:12:58

标签: c# .net xamarin.forms .net-standard-1.4

我有以下代码

try 
{
    naughtyMethod();
} 
catch (Exception e)
{
    System.Diagnostics.Debug.WriteLine("Error");
    System.Diagnostics.Debug.WriteLine("Error" + e.Message);
    // System.Diagnostics.Debug.WriteLine("Error" + e.ToString()); // causes an exception
    // System.Diagnostics.Debug.WriteLine("Error" + e.StackTrace); // causes an exception
}

后两行抛出异常:

  

System.IO.FileLoadException:'无法加载文件或程序集   'System.Core,Version = 4.0.0.0,Culture = neutral,   公钥= b77a5c561934e089' 。找到的程序集清单   定义与程序集引用不匹配。 (例外   HRESULT:0x80131040)'

它是一个带有.Net标准1.4的Xamarin应用程序。

有什么方法吗?我需要记录堆栈跟踪。

有趣的是,如果我之前添加了一个断点,我可以在调试器中查看e.StackTrace

0 个答案:

没有答案