【问题标题】:Where to put global exception handler in Gtk# application?在 Gtk# 应用程序中将全局异常处理程序放在哪里?
【发布时间】:2013-01-06 15:39:34
【问题描述】:

我已经使用 MonoDevelop 开始了新的 Gtk# 解决方案。现在我可以在哪里放置 global 异常处理程序,该处理程序会向用户弹出带有堆栈跟踪等的对话框?是否有任何现有的库可以做到这一点?

类似https://exceptionreporter.codeplex.com/

Main.cs:

using System;
using Gtk;

namespace foobar
{
    class MainClass
    {
        public static void Main (string[] args)
        {
            Application.Init ();
            MainWindow win = new MainWindow ();
            win.Show ();
            Application.Run ();
        }
    }
}

MainWindow.cs:

using System;
using Gtk;

public partial class MainWindow: Gtk.Window
{   
    public MainWindow (): base (Gtk.WindowType.Toplevel)
    {
        Build ();
    }

    protected void OnDeleteEvent (object sender, DeleteEventArgs a)
    {
        Application.Quit ();
        a.RetVal = true;
    }
}

【问题讨论】:

    标签: c# exception-handling error-handling gtk#


    【解决方案1】:

    您可以使用GLib.ExceptionManager.UnhandledException event

    它的argument of type GLib.UnhandledExceptionArgs Class 包含一个ExitApplication property,可用于控制应用程序是否应因异常而退出。

    【讨论】:

      猜你喜欢
      • 2019-07-26
      • 1970-01-01
      • 1970-01-01
      • 2010-10-19
      • 1970-01-01
      • 2012-06-05
      • 2011-04-07
      • 2011-01-23
      • 2014-04-17
      相关资源
      最近更新 更多