When working on ASP.NET 1.1 projects I always used the Global.asax to catch all errors. I'm looking for a similar way to catch all exceptions in a Windows Forms user control, which ends up being a hosted IE control. What is the proper way to go about doing something like this?
相关问题
- How do I bind a DataGridViewComboBoxColumn to a pr
- Partial Form Class C# - Only display code view for
- How do I identify what code is generating “ '&
- Can we add four protocols to ServicePointManager.S
- How to properly handle form closing when using bac
相关文章
- Sort TreeView Automatically Upon Adding Nodes
- Where does this quality loss on Images come from?
- Missing partial modifier on declaration of type
- <link> onerror do not work in IE
- PropertyGrid - Possible to have a file/directory s
- Why do base Windows Forms form class with generic
- How to handle the TextChanged event only when the
- Could not find default endpoint element that refer
You need to handle the
System.Windows.Forms.Application.ThreadException
event for Windows Forms. This article really helped me: http://bytes.com/forum/thread236199.html.To Handle Exceptions Globally...
Windows Application
System.Windows.Forms.Application.ThreadException event
Generally Used in Main Method. Refer MSDN Thread Exception
Asp.Net
System.Web.HttpApplication.Error event
Normally Used in Global.asax file. Refer MSDN Global.asax Global Handlers
Console Application
System.AppDomain.UnhandledException event
Generally used in Main Method. Refer MSDN UnhandledException
If you're using VB.NET, you can tap into the very convenient ApplicationEvents.vb. This file comes for free with a VB.NET WinForms project and contains a method for handling unhandled exceptions.
To get to this nifty file, it's "Project Properties >> Application >> Application Events"
If you're not using VB.NET, then yeah, it's handling Application.ThreadException.
Currently in my winforms app I have handlers for
Application.ThreadException
, as above, but alsoAppDomain.CurrentDomain.UnhandledException
Most exceptions arrive via the
ThreadException
handler, but the AppDomain one has also caught a few in my experienceCode from MSDN: http://msdn.microsoft.com/en-us/library/system.appdomain.unhandledexception.aspx?cs-save-lang=1&cs-lang=vb#code-snippet-2