小技巧备忘
public partial class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
RegisterExceptionEvents();
base.OnStartup(e);
}
private void RegisterExceptionEvents()
{
DispatcherUnhandledException += (sender, args) =>
{
new ExceptionMessageBox(args.Exception.Message);
args.Handled = true;
};
TaskScheduler.UnobservedTaskException += (sender, args) =>
{
new ExceptionMessageBox(args.Exception.Message);
args.SetObserved();
};
AppDomain.CurrentDomain.UnhandledException += (sender, args) =>
{
new ExceptionMessageBox((args.ExceptionObject is Exception) ?
((Exception)args.ExceptionObject).Message : args.ExceptionObject.ToString());
};
}