使用DispatcherUnhandledException捕捉未经处理的异常
using System.Windows; namespace Test02
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e); this.DispatcherUnhandledException += App_DispatcherUnhandledException;
} void App_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
{
MessageBox.Show(e.Exception.Message);
}
}
}