title: Catching ThreadingException in VB.NET when Sub Main is not accessible
body: <p>I have a VB.NET winforms solution, and would like to add the standard application exception handlers - <code>Application.ThreadException</code> and <code>AppDomain.CurrentDomain.UnhandledException</code>.</p>
  
  <p>I have the following code <a href="http://msdn.microsoft.com/fr-fr/library/system.windows.forms.application.threadexception.aspx" rel="noreferrer">from MSDN</a></p>
  
  <pre><code>' Starts the application. '
  &lt;SecurityPermission(SecurityAction.Demand, Flags:=SecurityPermissionFlag.ControlAppDomain)&gt; _
  Public Shared Sub Main()
      ' Add the event handler for handling UI thread exceptions to the event. '
      AddHandler Application.ThreadException, AddressOf ErrorHandlerForm.Form1_UIThreadException
  
      ' Set the unhandled exception mode to force all Windows Forms errors to go through'
      ' our handler. '
      Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException)
  
      ' Add the event handler for handling non-UI thread exceptions to the event. '
      AddHandler AppDomain.CurrentDomain.UnhandledException, AddressOf CurrentDomain_UnhandledException
  
      ' Runs the application. '
      Application.Run(New ErrorHandlerForm())
  End Sub
  </code></pre>
  
  <p>How can I do it in VB.NET when I have no acces to the <code>Sub Main()</code> method?</p>
  
  <p>Is the case when "Enable Application Framework" of my solution properties is enabled (<code>Sub Main</code> is hidden)...</p>