Application.ThreadException和AppDomain.CurrentDomain.UnhandledException都不符合 [英] Neither Application.ThreadException nor AppDomain.CurrentDomain.UnhandledException are respected

查看:179
本文介绍了Application.ThreadException和AppDomain.CurrentDomain.UnhandledException都不符合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,在 Program.Program()静态构造函数中,我有以下代码:

First, within the Program.Program() static constructor I have this code:

AppDomain.CurrentDomain.UnhandledException += (s, eargs) =>
    LogException((Exception)eargs.ExceptionObject);
Application.ThreadException +=
    (s, eargs) => LogException(eargs.Exception);

然后,如果我故意(例如)做了一个除以零,就被抓住了。但是,线程循环中的其他异常都不会被捕获,就像这样,它的堆栈跟踪是:

Then, if I deliberately do (for example) a divide-by-zero, it's caught. However, none of the other exceptions from within the thread loop are caught, like this one - its stack trace is:

System.ComponentModel.ReflectPropertyDescriptor.GetValue(component = {My.Component})    
System.Windows.Forms.BindToObject.GetValue()    
System.Windows.Forms.Binding.PushData(force)    
System.Windows.Forms.Binding.UpdateIsBinding()  
System.Windows.Forms.Binding.CheckBinding() 
System.Windows.Forms.Binding.SetListManager(bindingManagerBase) 
System.Windows.Forms.ListManagerBindingsCollection.AddCore(dataBinding = {System.Windows.Forms.Binding})    
System.Windows.Forms.BindingsCollection.Add(binding)    
System.Windows.Forms.BindingContext.UpdateBinding(newBindingContext, binding)   
System.Windows.Forms.Control.UpdateBindings()   
System.Windows.Forms.Control.OnBindingContextChanged(e = {System.EventArgs})    
System.Windows.Forms.Control.OnParentBindingContextChanged(e)   
System.Windows.Forms.Control.OnBindingContextChanged(e = {System.EventArgs})    
System.Windows.Forms.Control.OnParentBindingContextChanged(e)   
System.Windows.Forms.Control.OnBindingContextChanged(e = {System.EventArgs})    
System.Windows.Forms.Control.OnParentBindingContextChanged(e)   
System.Windows.Forms.Control.OnBindingContextChanged(e = {System.EventArgs})    
System.Windows.Forms.Control.OnParentBindingContextChanged(e)   
System.Windows.Forms.Control.OnBindingContextChanged(e = {System.EventArgs})    
System.Windows.Forms.Control.CreateControl()    
System.Windows.Forms.Control.SetVisibleCore(value = true)   
System.Windows.Forms.TabPage.Visible.set(value) 
System.Windows.Forms.TabControl.UpdateTabSelection(updateFocus = false) 
System.Windows.Forms.TabControl.OnHandleCreated(e)  
System.Windows.Forms.Control.WmCreate(m)    
System.Windows.Forms.Control.WndProc(m) 
System.Windows.Forms.TabControl.WndProc(m)  
System.Windows.Forms.Control.ControlNativeWindow.OnMessage(m)   
System.Windows.Forms.Control.ControlNativeWindow.WndProc(m) 
System.Windows.Forms.NativeWindow.Callback(hWnd, msg = 0x00000001, wparam, lparam)  
[Native to Managed Transition]  
[Managed to Native Transition]  
System.Windows.Forms.UnsafeNativeMethods.CreateWindowEx(dwExStyle, lpszClassName, lpszWindowName, style, x, y, width, height, hWndParent, hMenu, hInst, pvParam)    
System.Windows.Forms.NativeWindow.CreateHandle(cp)  
System.Windows.Forms.Control.CreateHandle() 
System.Windows.Forms.TabControl.CreateHandle()  
System.Windows.Forms.Control.CreateControl(fIgnoreVisible = false)  
System.Windows.Forms.Control.CreateControl(fIgnoreVisible = false)  
System.Windows.Forms.Control.CreateControl(fIgnoreVisible = false)  
System.Windows.Forms.Control.CreateControl(fIgnoreVisible = false)  
System.Windows.Forms.Control.CreateControl()    
System.Windows.Forms.Control.WmShowWindow(m)    
System.Windows.Forms.Control.WndProc(m) 
System.Windows.Forms.ScrollableControl.WndProc(m)   
System.Windows.Forms.ContainerControl.WndProc(m)    
System.Windows.Forms.Form.WmShowWindow(m)   
System.Windows.Forms.Form.WndProc(m)    
System.Windows.Forms.Control.ControlNativeWindow.OnMessage(m)   
System.Windows.Forms.Control.ControlNativeWindow.WndProc(m) 
System.Windows.Forms.NativeWindow.Callback(hWnd, msg = 0x00000018, wparam, lparam)  
[Native to Managed Transition]  
[Managed to Native Transition]  
System.Windows.Forms.Control.SetVisibleCore(value = true)   
System.Windows.Forms.Form.SetVisibleCore(value = true)  
System.Windows.Forms.Control.Visible.set(value) 
System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(reason = 0xffffffff, context = {System.Windows.Forms.ApplicationContext})    
System.Windows.Forms.Application.ThreadContext.RunMessageLoop(reason, context)  
System.Windows.Forms.Application.Run(mainForm)  
My.Namespace.Program.Main()
[Native to Managed Transition]  
[Managed to Native Transition]  
System.AppDomain.ExecuteAssembly(assemblyFile, assemblySecurity, args)  
Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()   
System.Threading.ThreadHelper.ThreadStart_Context(state)    
System.Threading.ExecutionContext.Run(executionContext, callback, state)    
System.Threading.ThreadHelper.ThreadStart() 

ReflectPropertyDescriptor 调用我的代码并抛出一个自定义异常时,系统会静默地吞下它,我无法登录。

When that ReflectPropertyDescriptor calls my code and I throw a custom exception, the system silently swallows it and I can't log it.

推荐答案

事实证明,我的大部分丢失的例外可以在 BindingComplete 事件中看到。它必须做。

It turns out that the majority of my lost exceptions can be seen in the BindingComplete event. It'll have to do.

这篇关于Application.ThreadException和AppDomain.CurrentDomain.UnhandledException都不符合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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