久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

C# 中的靜默失敗,看似未處理的異常,不會使程

Silent failures in C#, seemingly unhandled exceptions that does not crash the program(C# 中的靜默失敗,看似未處理的異常,不會使程序崩潰)
本文介紹了C# 中的靜默失敗,看似未處理的異常,不會使程序崩潰的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

在 winforms 應(yīng)用中,在表單的 Load 事件中,添加以下行:

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

throw new Exception();

并運行應(yīng)用程序.它運行沒有問題.這稱為靜默失敗,您可以嘗試在前后添加消息框,您很快就會發(fā)現(xiàn) throw 語句并沒有讓應(yīng)用程序崩潰,而是從 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.

我仍然想知道這種可怕行為背后的(可能是歷史)原因.我確信這不是設(shè)計決定,可能是沒有選擇,或者是懶惰.有人知道嗎?

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?

如果有人能指出可能導(dǎo)致 seileent 失敗的事件列表,我會很高興.

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

這是我的代碼片段 - 我不知道它有什么幫助 - 但是,這里是:

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);
        }

    }
}

編輯似乎它并沒有發(fā)生在每個人身上.我用的是:fw 3.5, winforms, vs 2008, vista x64, new clean project of winforms,上面的代碼.

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 系統(tǒng)上的已知問題:

這是 64 位操作系統(tǒng)上的已知問題平臺.原因是64位操作系統(tǒng)內(nèi)核不允許用戶模式通過內(nèi)核模式堆棧的異常.異常被操作系統(tǒng)吞噬悄悄地.這發(fā)生在 FormLoad處理程序,因為它是在操作系統(tǒng)中調(diào)用的打回來.32位操作系統(tǒng)不這樣做,所以它不會在那里重現(xiàn).

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.

操作系統(tǒng)團(tuán)隊正在調(diào)查相關(guān)的問題.與此同時,你確實有解決這個問題.開啟停止第一次機會例外"將使調(diào)試器在此停止設(shè)想.但它確實使調(diào)試器經(jīng)常停止,所以你可能只想在您這樣做時發(fā)現(xiàn)問題.

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 月,并沒有說明從那以后發(fā)生了什么.

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

我可以在這里重現(xiàn)大多數(shù)海報在我的 32 位系統(tǒng)上的行為,并且我可以在我的 64 位(Vista SP2、3.5SP1 框架)工作 PC 上重現(xiàn) OP 的行為.

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.

這篇關(guān)于C# 中的靜默失敗,看似未處理的異常,不會使程序崩潰的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Is there a C# library that will perform the Excel NORMINV function?(是否有執(zhí)行 Excel NORMINV 函數(shù)的 C# 庫?)
Select x random elements from a weighted list in C# (without replacement)(從 C# 中的加權(quán)列表中選擇 x 個隨機元素(無需替換))
Create a summary description of a schedule given a list of shifts(給定輪班列表,創(chuàng)建時間表的摘要描述)
C# Normal Random Number(C# 普通隨機數(shù))
Standard deviation of generic list?(通用列表的標(biāo)準(zhǔn)偏差?)
AsyncCTP: Creating a class that is IAwaitable(AsyncCTP:創(chuàng)建一個 IAwaitable 的類)
主站蜘蛛池模板: av中文字幕在线 | 精品一区二区在线观看 | 久久久精 | 亚洲成av人片在线观看无码 | 四虎影音| 大象一区 | 热re99久久精品国产99热 | av国产精品 | 亚洲精品一区二区三区在线观看 | 精品亚洲一区二区三区四区五区高 | 在线观看免费av网 | 岛国av一区二区 | 欧美激情一区二区 | 亚洲免费人成在线视频观看 | 欧美精品1区2区3区 精品国产欧美一区二区 | 亚洲欧美日韩中文字幕一区二区三区 | 国产精品久久久久久福利一牛影视 | 欧美一区二区三区视频 | 中文字幕在线播放不卡 | 能看的av | 久久久久久久久久久国产 | 人人澡人人射 | 国产aⅴ爽av久久久久久久 | 日韩免费一区 | 午夜av成人 | av天天澡天天爽天天av | 成人精品国产一区二区4080 | 欧美综合国产精品久久丁香 | 欧美中文字幕在线 | 国产黄色网址在线观看 | 一区二区三区国产精品 | 国产电影一区二区 | 亚洲综合色视频在线观看 | www.日韩av.com | 日韩视频国产 | 国产在线一区二区三区 | 久久一区 | 国产欧美一区二区三区日本久久久 | 91免费观看| 亚洲日本免费 | 国产成人精品亚洲日本在线观看 |