zoukankan      html  css  js  c++  java
  • WPF异常捕获三种处理 UI线程, 全局异常,Task异常

    protected override void OnStartup(StartupEventArgs e)
    {
    base.OnStartup(e);
    RegisterEvents();
    }

    private void RegisterEvents()
    {
    //TaskScheduler.UnobservedTaskException += (sender, args) =>
    //{
    // MessageBox.Show(args.Exception.Message);
    // args.SetObserved();
    //};

    this.DispatcherUnhandledException += App_DispatcherUnhandledException;
    TaskScheduler.UnobservedTaskException += new EventHandler<
    UnobservedTaskExceptionEventArgs>(TaskScheduler_UnobservedTaskException);

    AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
    }

    private void App_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
    {

    }

    static void TaskScheduler_UnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs e)
    {
    foreach (Exception item in e.Exception.InnerExceptions)
    {
    Console.WriteLine("异常类型:{0}{1}来自:{2}{3}异常内容:{4}",
    item.GetType(), Environment.NewLine, item.Source,
    Environment.NewLine, item.Message);
    }
    //将异常标识为已经观察到 
    e.SetObserved();
    }

    private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
    {
    MessageBox.Show("Unhandled exception.");
    }

  • 相关阅读:
    优先队列(堆)
    从CPU管理到进程的引入
    倾听程序员
    数据库设计
    数据库设计之数据库,数据表和字段等的命名总结
    Set容器--HashSet集合
    Java Collection开发技巧
    关于事务
    关于触发器
    windows phone(成语典籍游戏开发)
  • 原文地址:https://www.cnblogs.com/francis-gao/p/9500341.html
Copyright © 2011-2022 走看看