<p>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?</p>

[{'answer_id': 2779, 'author': 'Chris Leon', 'author_id': 289, 'author_profile': 'https://Stackoverflow.com/users/289', 'pm_score': 6, 'selected': True, 'text': '<p>You need to handle the <code>System.Windows.Forms.Application.ThreadException</code> event for Windows Forms. This article really helped me: <a href="http://bytes.com/forum/thread236199.html" rel="noreferrer">http://bytes.com/forum/thread236199.html</a>.</p>\n'}, {'answer_id': 2790, 'author': 'Brad Tutterow', 'author_id': 308, 'author_profile': 'https://Stackoverflow.com/users/308', 'pm_score': 3, 'selected': False, 'text': '<p>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 <a href="http://msdn.microsoft.com/en-us/library/3a02k5s0(VS.80).aspx" rel="noreferrer">unhandled exceptions</a>.</p>\n\n<p>To get to this nifty file, it\'s "Project Properties >> Application >> Application Events"</p>\n\n<p>If you\'re not using VB.NET, then yeah, it\'s handling <a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.application.threadexception.aspx" rel="noreferrer">Application.ThreadException</a>.</p>\n'}, {'answer_id': 2817, 'author': 'Orion Edwards', 'author_id': 234, 'author_profile': 'https://Stackoverflow.com/users/234', 'pm_score': 4, 'selected': False, 'text': '<p>Currently in my winforms app I have handlers for <code>Application.ThreadException</code>, as above, but also <code>AppDomain.CurrentDomain.UnhandledException</code></p>\n<p>Most exceptions arrive via the <code>ThreadException</code> handler, but the AppDomain  has also caught a few in my experience</p>\n'}, {'answer_id': 19060702, 'author': 'Aaron Hoffman', 'author_id': 47226, 'author_profile': 'https://Stackoverflow.com/users/47226', 'pm_score': 2, 'selected': False, 'text': '<p>Code from MSDN: <a href="http://msdn.microsoft.com/en-us/library/system.appdomain.unhandledexception.aspx?cs-save-lang=1&amp;cs-lang=vb#code-snippet-2" rel="nofollow">http://msdn.microsoft.com/en-us/library/system.appdomain.unhandledexception.aspx?cs-save-lang=1&amp;cs-lang=vb#code-snippet-2</a></p>\n\n<pre><code>Sub Main()\n  Dim currentDomain As AppDomain = AppDomain.CurrentDomain\n  AddHandler currentDomain.UnhandledException, AddressOf MyHandler\n\n  Try \n     Throw New Exception("1")\n  Catch e As Exception\n     Console.WriteLine("Catch clause caught : " + e.Message)\n     Console.WriteLine()\n  End Try \n\n  Throw New Exception("2")\nEnd Sub \n\nSub MyHandler(sender As Object, args As UnhandledExceptionEventArgs)\n  Dim e As Exception = DirectCast(args.ExceptionObject, Exception)\n  Console.WriteLine("MyHandler caught : " + e.Message)\n  Console.WriteLine("Runtime terminating: {0}", args.IsTerminating)\nEnd Sub \n</code></pre>\n'}, {'answer_id': 30324516, 'author': 'Ajay', 'author_id': 2359385, 'author_profile': 'https://Stackoverflow.com/users/2359385', 'pm_score': 2, 'selected': False, 'text': '<p>To Handle Exceptions Globally...</p>\n\n<p><strong>Windows Application</strong></p>\n\n<p>System.Windows.Forms.Application.ThreadException event</p>\n\n<p><em>Generally Used in Main Method. Refer <a href="https://msdn.microsoft.com/en-us/library/system.windows.forms.application.threadexception.aspx" rel="nofollow">MSDN Thread Exception</a></em></p>\n\n<p><strong>Asp.Net</strong></p>\n\n<p>System.Web.HttpApplication.Error event</p>\n\n<p><em>Normally Used in Global.asax file. Refer <a href="https://msdn.microsoft.com/en-us/library/24395wz3(v=vs.140).aspx" rel="nofollow">MSDN Global.asax Global Handlers</a></em></p>\n\n<p><strong>Console Application</strong></p>\n\n<p>System.AppDomain.UnhandledException event</p>\n\n<p><em>Generally used in Main Method. Refer <a href="https://msdn.microsoft.com/en-us/library/system.appdomain.unhandledexception.aspx" rel="nofollow">MSDN UnhandledException</a></em> </p>\n'}]
['https://Stackoverflow.com/questions/2770', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/447/']