沉默的例外, [英] Silent exception,

查看:35
本文介绍了沉默的例外,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 64 位中遇到过这个奇怪的静默异常问题.是什么导致了这种行为?我想了解为什么会发生这种情况以及推荐的解决方案是什么?

I've encountered this weird issue of silent exceptions in 64 bit. What is that cause this bahavior? I would like to understand why does this occur and what is the recommended solution?

主要内容:

    try
    {
        Application.Run(new Form1());
    }
    catch
        (Exception ex)
    {
        MessageBox.Show("Error");
    }

private void Form1_Load(object sender, EventArgs e)
{
    throw new Exception("oh no!");
}

推荐答案

为了加载一个表单,你的代码会调用内核函数来创建窗体的窗口,而这个内核函数又会回调到你的代码中通过发送调用您的 OnLoad 方法的消息.如果在该方法中抛出异常,异常处理机制会将调用堆栈返回到内核模式边界.

In order to load a form, your code will call into a kernel function to create the form's window, and this kernel function will in turn call back into your code by sending a message that invokes your OnLoad method. If you throw an exception in that method, the exception handling mechanism walks the call stack back to the kernel mode boundary.

在 x86 上,异常可以通过此边界并返回到原始调用者.在 x64 上,它在到达边界时停止并且无法继续.在 XP64 和 Vista 中,异常被吞下(忽略),而带有清单的 64 位应用程序表明它与 Win7 兼容会在发生这种情况时崩溃.要获取其他操作系统上的崩溃行为或 64 位 Win7 上的 32 位应用程序的崩溃行为,请参阅 KB976038.

On x86 an exception can go through this boundary and back to the original caller. On x64 it stops when it hits the boundary and cannot continue. In XP64 and Vista the exception was swallowed (ignored), while a 64-bit app with a manifest saying it is Win7-compatible will crash when this happens. To get the crashing behavior on other OSes or for 32-bit apps on 64-bit Win7, see KB976038.

对于在 x64 上作为内核模式回调调用的任何事件处理程序都会发生这种行为.

This behavior will happen for any event handler that is invoked as a callback from kernel mode on x64.

这篇关于沉默的例外,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆