title: ThreadExceptionHandler not catching exception in MainFrm constructor
body: <p>I have a test winforms app with ThreadExceptionHandler that displays a message box when an unhandled exception is caught, as follows:</p>
  
  <pre><code>[STAThread]
  static void Main()
  {
      Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
      Application.EnableVisualStyles();
      Application.SetCompatibleTextRenderingDefault(false);
      Application.Run(new Form1());
  }
  
  static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
  {
      MessageBox.Show("error caught");
  }
  </code></pre>
  
  <p>When I force an error in the ctor of Form 1 (e.g. dividebyzero) as follows:</p>
  
  <pre><code>public Form1()
  {
       InitializeComponent();
  
       int i = 0;
       int x = 5 / i;
  }
  </code></pre>
  
  <p>and run the app outside of Visual Studio (in Windows 7), the divide by zero exception is <em>not</em> handled - I get an unhelpful "WindowsFormApplication1 has stopped working..." message.</p>
  
  <p><em>However</em>, when I move the dividebyzero exception to the Form1_Load event and rerun, the exception is handled properly.</p>
  
  <p>Can someone explain why this is the case? The reason I ran this test program is because I am experiencing a similar unhandled exception issue in another, enterprise app that I am trying to track down.</p>