C#第一次机会异常不完整的堆栈跟踪

时间:2017-10-26 10:06:23

标签: c# .net exception unhandled-exception first-chance-exception

我有一个带有以下代码的Windows服务

application.rb

Inside Test方法catch我可以看到完整的堆栈跟踪

AppDomain.CurrentDomain.FirstChanceException += CurrentDomain_FirstChanceException;
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

private static void CurrentDomain_FirstChanceException(object sender, System.Runtime.ExceptionServices.FirstChanceExceptionEventArgs e)
    {
          if (e.Exception == null)
            return;

          LogException(e.Exception, "FirstChance Exception ");
    }

    public void Test()
    {
      Task.Factory.StartNew(x =>
            {
               foreach(item in blockingCollection.GetConsumingEnumerable())
               {
                  try
                  {
                     Convert.ToInt32("Test");
                  }
                  catch (Exception ex)
                  {
                  }
               }
            });            
        }

而在 at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info) at System.Convert.ToInt32(String value) at Test.TestService.<QueueConsumer>b__11_0(Object x) in C:\SourceControl\TestProject.Risk\Application\TestService.cs:line 157 中,我看到不完整的堆栈跟踪

private static void CurrentDomain_FirstChanceException

如果我删除System.FormatException: Input string was not in a correct format. at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) CurrentDomain_UnhandledException事件未被触发

我想避免try {} catch {}只是为了记录异常。如何在第一次机会异常中获得完整的堆栈跟踪?

0 个答案:

没有答案
相关问题