我在 WinForms 上有一个带有以下代码的项目:
AppDomain.CurrentDomain.UnhandledException += CurrentDomainUnhandledException;
private void CurrentDomainUnhandledException(object sender, UnhandledExceptionEventArgs e)
{ }
e.ExceptionObject
包含完整的 StackTrace。在 Win Store 项目中:
this.UnhandledException += (s, e) =>{
{
MarkedUp.AnalyticClient.LogLastChanceException(e);
};
e.Exception.StackTrace 为空。
这两个异常都是由这段代码生成的:
int a=0;
....
try
{
int i = 1 / a;
}
catch (Exception exp)
{
throw;
}
有任何想法吗?
最佳答案
您是否在 Debug模式下运行解决方案?当您在 Debug模式下运行解决方案时,App.g.i.cs 文件中似乎发生了一些事情。当我在 Release 模式下运行您的示例时,堆栈跟踪在 UnhandledException 事件中可用。
在我的测试解决方案中,它首先在这里中断:
#if DEBUG && !DISABLE_XAML_GENERATED_BREAK_ON_UNHANDLED_EXCEPTION
UnhandledException += (sender, e) =>
{
if (global::System.Diagnostics.Debugger.IsAttached) global::System.Diagnostics.Debugger.Break();
};
#endif
在那之后,它转到我在 app.xaml.cs 文件中定义的 UnhandledException 处理程序。在调试中堆栈跟踪消失了,在 Release模式中堆栈跟踪和异常详细信息在那里。
关于windows-runtime - WinRt。 UnhandledException 处理程序。堆栈跟踪为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16936305/