0
我在我們的應用程序中遇到了一個根本沒有處理的異常。我真的不知道該如何調試這個問題,因爲當這個特殊的異常拋出時(即使是從VS運行),應用程序立即關閉。異常處理是設置這樣:AppDomain.CurrentDomain.UnhandledException並不總是觸發
[STAThread]
[LoaderOptimizationAttribute(LoaderOptimization.MultiDomainHost)]
static void Main()
{
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
Application.ApplicationExit += new EventHandler(ApplicationExitHandler);
Application.ThreadException += new ThreadExceptionEventHandler(ThreadExceptionHandler);
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(UnhandledExceptionHandler);
...
從中拋出異常時就這樣開始了螺紋:
Thread executerThread = new Thread(new ThreadStart(modele.Exporter));
executerThread.SetApartmentState(ApartmentState.STA);
executerThread.Start();
現在,每當未處理的異常從該線程火起來我們UnhandledExceptionHandler除了拋出一個我有問題。即使我發現有問題的異常並再次拋出,應用程序也會自動關閉。 3個處理程序(ApplicationExit,ThreadException,UnhandledException)都沒有被觸發(斷點未命中)。
在這個例外中沒有什麼特別的(詳情請見:http://pastebin.com/fCnDRRiJ)。
你幾乎肯定是正確的。我能做的最好的事情就是直接在線程中處理異常。這意味着我們不能信任AppDomain.CurrentDomain.UnhandledException來記錄所有內容。 – 2010-03-19 13:30:07
我仍然覺得奇怪的是,如果我發現異常,應用程序可以繼續正常工作。就好像是某個地方設置了某個標誌,表示「下一次你得到一個未處理的異常,就關閉」。這沒有多大意義。 – 2010-03-19 13:35:38