【问题标题】:Silent exception,沉默的例外,
【发布时间】:2010-12-21 07:36:44
【问题描述】:

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

主要:

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

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

【问题讨论】:

  • Unfortunately where is nothing that the Visual Studo team can do to address this, it is the result of operating system design. All feedback regarding this issue should be addressed to the Windows team; however the Windows team considers this to be the "correct" operating system design, and considers the x86 behavior to be "incorrect"哈哈。微软不错。 请就此与其他团队联系,但他们不会修复它,因为他们认为第三团队实施不正确。
  • 实际上第二篇文章对问题和解决方案都进行了很好的深入解释。
  • 显然有一个修补程序(链接到您提供的链接中)。

标签: c# exception-handling 64-bit


【解决方案1】:

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

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

对于从 x64 上的内核模式作为回调调用的任何事件处理程序,都会发生此行为。

【讨论】:

  • user271077:这很复杂 :) 阅读页面顶部的第一个链接了解所有详细信息
猜你喜欢
  • 1970-01-01
  • 2022-01-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-04-20
  • 2020-01-22
相关资源
最近更新 更多