无声故障在C#中,看似未处理的异常是不会崩溃的程序 [英] Silent failures in C#, seemingly unhandled exceptions that does not crash the program

查看:204
本文介绍了无声故障在C#中,看似未处理的异常是不会崩溃的程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个WinForms应用程序,在窗体的Load事件,添加以下行:

In a winforms app, in a form's Load event, add the following line:

throw new Exception();

和运行应用程序。其运行没有任何问题。这就是所谓的无声故障,您可以尝试之前和之后添加提示消息框,你很快就会发现,而不是崩溃的应用程序,throw语句刚刚从Load事件退出。

and run the application. It ran without a problem. This is called a silent failure, you can try to add messageboxes before and after, and you'll soon find out that instead of crashing the application, the throw statement just exits from the Load event.

我敢肯定,有没有必要解释多么丑陋的和危险的,这是。

I'm sure there is no need to explain how ugly and dangerous this is.

我在想,但是在(可能是历史上)这背后的恐怖行为的原因。 我敢肯定,这不是一个设计决策,很可能没有选择,或者懒惰。有谁知道?

I was wondering nonetheless in the (probably history) reasons behind this terrifying behavior. I'm sure it's not a design decision, probably no-choice, or laziness. Does anybody know?

。将很高兴,如果有人能指点事件列表,它可能会导致seilent失败了。

Would be glad if anyone can point me to a list of events which may cause seilent failures too.

下面是我的code的片段 - 我不知道如何帮助 - 但是,在这里它是:

Here's a snippet of my code - I have no idea how it might help - but, here it is:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Form f = new Form();
            f.Load += new EventHandler((x, y) => { throw new Exception(); });
            Application.Run(f);
        }

    }
}

修改 现在看来,这并不happend给大家。 我用:FW 3.5,的WinForms,VS 2008,Vista 64位,WinForms的新型清洁工程,与上面提到的code

EDIT It seems it does not happend to everyone. I use: fw 3.5, winforms, vs 2008, vista x64, new clean project of winforms, with the code mentioned above.

推荐答案

这是一个已知的问题在x64系统的:

这是64位操作系统的一个已知的问题   平台。其原因是,64位   操作系统内核不允许用户模式   通过内核模式堆栈异常。   唯一的例外是由OS吞噬   sliently。这发生在FormLoad   处理程序中,因为它被称为一个操作系统   回电话。 32位操作系统不这样做,   因此它不REPRO那里

This is a known issue on 64-bit OS platform. The reason is that the 64bit OS core does not allow user mode exception through kernal mode stacks. The exception is swallowed by OS sliently. That happens in FormLoad handler, because it is called in an OS callback. 32bits OS doesn't do this, so it doesn't repro there.

操作系统团队正在调查相关   的问题。在此同时,你必须   要解决此问题。开启   停止在第一次机会异常,将   使调试器停止在此   场景。但它确实使   调试器停止非常频繁,所以你   可能希望只有做到这一点,当你   发现一个问题。

The OS team is investigating related issues. In the mean time, you do have to work around this issue. Turning on "Stop on first chance exception" will make the debugger to stop in this scenario. But it does make the debugger to stop very often, so you might want to do this only when you find a problem.

该链接错误报告是去年更新2008年2月,并不表示自那以后发生了什么事。

The linked bug report was last updated February 2008, and doesn't indicate what's happened since then.

我可以重现最发表者的行为对我的32位系统在这里,我可以重现OP的行为在我的64位(Vista SP2的,3.5SP1框架)的工作电脑。

I can reproduce most poster's behavior on my 32-bit system here, and I can reproduce the OP's behavior on my 64-bit (Vista SP2, 3.5SP1 Framework) work PC.

这篇关于无声故障在C#中,看似未处理的异常是不会崩溃的程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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