title: How to use ThreadException?
body: <p>I tried using</p>
  
  <p><a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.application.threadexception.aspx#Y399" rel="nofollow">http://msdn.microsoft.com/en-us/library/system.windows.forms.application.threadexception.aspx#Y399</a></p>
  
  <p>but when I do this </p>
  
  <pre><code>throw new ArgumentNullException("playlist is empty");
  </code></pre>
  
  <p>I get nothing. I bet I'm missing something very obvious.</p>
  
  <p>here is my code.</p>
  
  <pre><code>using System;
  using System.Security.Permissions;
  using System.Windows.Forms;
  using System.Threading;
  
  namespace MediaPlayer.NET
  {
      internal static class Program
      {
          /// &lt;summary&gt;
          /// The main entry point for the application.
          /// &lt;/summary&gt;
          [STAThread]
          [SecurityPermission(SecurityAction.Demand, Flags = SecurityPermissionFlag.ControlAppDomain)]
          private static void Main()
          {
              // Add the event handler for handling UI thread exceptions to the event.
              Application.ThreadException += new ThreadExceptionEventHandler(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. 
              AppDomain.CurrentDomain.UnhandledException +=
                  new UnhandledExceptionEventHandler(UnhandledException);
  
              Application.EnableVisualStyles();
              Application.SetCompatibleTextRenderingDefault(false);
              Application.Run(new MediaPlayerForm());
          }
  
          private static void UnhandledException(object sender, UnhandledExceptionEventArgs e)
          {
              MessageBox.Show("UnhandledException!!!!");
          }
  
          private static void UIThreadException(object sender, ThreadExceptionEventArgs t)
          {
              MessageBox.Show("UIThreadException!!!!",
                              "UIThreadException!!!!", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Stop);
              Application.Exit();
          }
      }
  }
  </code></pre>