Ни Application.ThreadException, ни AppDomain.CurrentDomain.UnhandledException не соблюдаются - PullRequest
0 голосов
/ 23 июля 2011

Во-первых, внутри статического конструктора Program.Program() у меня есть этот код:

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

Тогда, если я намеренно делаю (например) деление на ноль, это ловится. Тем не менее, ни одно из других исключений внутри цикла потока не перехватывается, как этот - его трассировка стека:

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 вызывает мой код, и я выбрасываю специальное исключение, система молча проглатывает его, и я не могу его зарегистрировать.

1 Ответ

0 голосов
/ 23 июля 2011

Оказывается, большинство моих потерянных исключений можно увидеть в событии BindingComplete. Это должно будет сделать.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...