title: How to catch unhandled exceptions in C#
body: <p>I have a service manager that checks and controls services that are connected to it. But sometimes one of my service is getting crushed and service manager can't know whether it is still working or not. (Because of the dialog box which shows debug and close options). So i found an accepted solution that catches unhandled exceptions, but doesn't work in my code.
  Here is my code that doesn't catch unhandled exceptions.</p>
  
  <pre><code>static void Main(string[] args) 
  {
    AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(unhandled_exceptions);
    new Thread(() =&gt; 
    {
        start()
    }).Start();
  
  }
  
  public void unhandled_exceptions(object sender, UnhandledExceptionEventArgs e) 
  {
    this.disconnect();
    logger.Error(e);
    logger.Info("Catched unhandled exception, that causes to crash application. Disconecting from service manager..");
    Environment.Exit(1);
  }
  
  public override void start() 
  {
    try 
    {
      throw new ArgumentException("erer");
    } 
    catch (Exception ex) 
    {
      logger.Error(ex);
    }
  
    Thread.Sleep(5000);
    PerformOverflow();
  
  }
  
  void PerformOverflow() 
  {
    PerformOverflow();
  }
  </code></pre>
  
  <p>.Net 4.6, Console applicaiton</p>
  
  <p>I don't know what causes to crash my application, in actual fact the start method is in a try catch blog. I am using StackOverflowException because it is not unhandled too. I think If i catch it i could catch the real one that crashes my app.</p>