IL_*_*ent 7 c# debugging unhandled-exception async-await uwp
我正在研究UWP应用程序.我正在使用异步/等待很多.总是在我的代码中发生异常时,调试器在App.gics中设置中断
#if DEBUG && !DISABLE_XAML_GENERATED_BREAK_ON_UNHANDLED_EXCEPTION
UnhandledException += (sender, e) =>
{
if (global::System.Diagnostics.Debugger.IsAttached) global::System.Diagnostics.Debugger.Break();
};
#endif
Run Code Online (Sandbox Code Playgroud)
但我希望在发生异常时看到该行.如何实现这种行为?
将以下方法添加到您的App类:
private static void UnhandledError(object sender, UnhandledErrorDetectedEventArgs eventArgs)
{
try
{
// A breakpoint here is generally uninformative
eventArgs.UnhandledError.Propagate();
}
catch (Exception e)
{
// Set a breakpoint here:
Debug.WriteLine("Error: {0}", e);
throw;
}
}
Run Code Online (Sandbox Code Playgroud)
在你的App构造函数中:
public UnitTestApp()
{
CoreApplication.UnhandledErrorDetected += UnhandledError;
// ...and any other initialization.
// The InitializeComponent call just sets up error handlers,
// and you can probably do without in the case of the App class.
// This can be useful for debugging XAML:
DebugSettings.IsBindingTracingEnabled = true;
DebugSettings.BindingFailed +=
(sender, args) => Debug.WriteLine(args.Message);
}
Run Code Online (Sandbox Code Playgroud)
仍然存在无法获得良好堆栈跟踪的情况,但这通常很有帮助.
另一种方法是在抛出异常时中断(通过Debug,Windows,Exception Settings).
| 归档时间: |
|
| 查看次数: |
961 次 |
| 最近记录: |