wpf - 未处理的异常

标签 wpf exception exception-handling unhandled-exception

在WPF应用程序中处理未处理的异常的最佳方法是什么?

最佳答案

您可以使用DispatcherUnhandledException:

XAML(App.xaml):

<Application x:Class="App.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    StartupUri="wndMain.xaml" DispatcherUnhandledException="Application_DispatcherUnhandledException">

背后的代码(App.xaml.cs/vb:
private void Application_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
{
    // Handle error here

    ...

    // Prevent default unhandled exception processing by WPF
    e.Handled = true;
}

阅读more here。但是,始终始终首先进行正确数量的错误处理。不要只让错误进入这种方法。

关于wpf - 未处理的异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2251868/

相关文章:

Java Try-With-Resources 辩论

wpf - 在 WPF 中使用命令绑定(bind)时处理异常的最佳做法是什么?

c# - 在 Prism 应用程序的多个模块中使用的模型应该放在哪里?

c# - WPF 复选框内容不正确

c# - 发布后 Clickonce 部署更改更新位置?

java - 当用户输入无效条目时,通过给出消息允许用户重试来发出错误异常

.net - 针对 WPF 应用程序的攻击

python - 有没有办法找出哪个 Python 方法可以引发哪个异常或错误

java - java异常会终止整个java应用程序吗?

php - 抑制 PDO 警告