防止 wxPython 显示“未处理的异常” 对话

发布于 2024-07-14 19:33:36 字数 1304 浏览 5 评论 0原文

我有用 Python 和 wxPython 编写的复杂 GUI 应用程序。

我希望它能够通过 Windows Vista 认证,因此它必须以某种方式崩溃,从而导致出现 Windows 错误报告对话框(询问“您想向 Microsoft 发送报告吗?”的对话框) 。 这与“Windows Vista 测试用例认证”文档中的第 32 号测试用例相关。

不幸的是,当我使用 ThreadHijacker 工具崩溃我的应用程序时,wxPython 显示如下消息:

Unhandled exception
---------------------------
An unhandled exception occurred. Press "Abort" to terminate the program,
"Retry" to exit the program normally and "Ignore" to try to continue.
---------------------------
Abort   Retry   Ignore

如何阻止 wxPython 显示此消息? 我有自定义的 sys.excepthook ,但似乎这个对话框是在我的 except 钩子干扰之前显示的。

编辑:

wxWidgets 文档 wxAppConsole::OnExceptionInMainLoop 被调用,并在 MSW 下显示一些奇特的对话框,允许用户在不同的选项之间进行选择。 然而,wxPython 似乎不允许重载该函数...有谁知道如何更改 wxPython 中的 wxAppConsole::OnExceptionInMainLoop 的默认行为?
与 C/C++ 中的解决方案相比,我更喜欢 Python 级别的解决方案

EDIT2:

总而言之,我在 wxPython 邮件列表中询问,Robin Dunn 回答说他会考虑制作 wxAppConsole::OnExceptionInMainLoop 可以在 wxPython 的下一个版本中重写。 因为我等不及了,所以我必须编译我自己的 wxPython 版本,它不包含该函数。 事实证明,可以通过正确设置编译标志来启用/禁用 wxAppConsole::OnExceptionInMainLoop 函数的存在。

I have complex GUI application written in Python and wxPython.

I want it to be certified for Windows Vista, so it has to crash in a way that causes Windows Error Reporting dialog (The one that asks "Do you want to send report to Microsoft?") to appear. This is relevant to test case no 32 from "Certified for Windows Vista Test Cases" document.

Unfortunately when I crash my app with ThreadHijacker tool wxPython shows message like:

Unhandled exception
---------------------------
An unhandled exception occurred. Press "Abort" to terminate the program,
"Retry" to exit the program normally and "Ignore" to try to continue.
---------------------------
Abort   Retry   Ignore

How can I prevent wxPython from showing this message? I have custom sys.excepthook, but it seems that this dialog is shown before my except hook can interfere.

EDIT:

wxWidgets docs says that wxAppConsole::OnExceptionInMainLoop is called and under MSW it displays some fancy dialog that allows user to choose between the different options. It seems however, that wxPython doesn't allow overloading that function... Does anyone know how to change default behaviour of wxAppConsole::OnExceptionInMainLoop in wxPython?
I prefer solutions that are on Python level over those that go into C/C++

EDIT2:

All in all, I asked at wxPython mailing list, and Robin Dunn answered that he'll look into making wxAppConsole::OnExceptionInMainLoop overridable in next releases of wxPython. Since I couldn't wait, I had to compile my own version of wxPython which does not include that function. It turned out that the presence of wxAppConsole::OnExceptionInMainLoop function can be enabled/disabled by proper setting of compilation flags.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

九命猫 2024-07-21 19:33:36

这一切最终都是编译我自己的 wxWidgets 和 wxPython,只更改了一个编译标志:wxUSE_EXCEPTIONS 应设置为 0。Robin

Dunn 写道,他将尝试修补 wxPython,因此可以修改此行为无需重新编译整个库。

It all ended up with compiling my own wxWidgets and wxPython, with just one compilation flag changed: wxUSE_EXCEPTIONS should be set to 0.

Robin Dunn wrote that he will try to patch wxPython, so this behaviour could be modified without recompiling of the whole library.

爱*していゐ 2024-07-21 19:33:36

如果我没记错的话,这是 wxWidgets 中顶层(wxApp)的一个 catch(...)。 您可以使用向量异常处理程序或 _set_se_translator() 来第一次处理结构化异常,并从那里退出到 WER,即 ReportFault()。

If I remember correctly, this is a catch(...) at top level (wxApp) in wxWidgets. You can either use a vectored Exception Handler or _set_se_translator() to get a first shot at the Structured Exception, and exit to WER, i.e. ReportFault() from there.

地狱即天堂 2024-07-21 19:33:36

难道你就可以包办一切吗? 我想,你必须在绑定到小部件的每个方法周围放置一个 try: except: 块。 您可以编写一个装饰器:

def catch_exception(f):
    def safe(*args, **kw):
        try:
            f(*args, **kw)
        except Exception, e:
            handle_exception(e)
    return safe

def handle_exception(e):
    # do Vista stuff
    sys.exit()

然后装饰主循环可以调用的任何函数(因为我认为这是 wxPython 自己进行捕获的地方)。

Is it possible for you to just handle everything? You would have to, I guess, put a try:except: block around every method bound to a widget. You could write a decorator:

def catch_exception(f):
    def safe(*args, **kw):
        try:
            f(*args, **kw)
        except Exception, e:
            handle_exception(e)
    return safe

def handle_exception(e):
    # do Vista stuff
    sys.exit()

Then decorate any function that could be called by the mainloop (since I presume that's where wxPython does its own catching).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文