title: ASP.NET Core 1.0 Global exception handler in console application (DNX)
body: <p>I'm trying to handle unhandled exceptions in asp.net 5 console application but I can't seem to catch these errors using the code believe. As soon as the exception is thrown the code breaks. Is there any way in a dnx app to catch unhandled exceptions?</p>
  
  <pre><code>public class Program
  {
      [STAThread]
      public static void Main(string[] args)
      {           
          #if !DNXCORE50
  
  
          // Register unhandled exception handler
          AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(UnhandledExceptionHandler);
  
          // Throw exception
          throw new Exception("1");
  
          #endif            
          Console.ReadLine();
      }
  
  
  
      #if !DNXCORE50
  
  
      /// &lt;summary&gt;
      ///  Catch all unhandled exceptions in all threads.
      /// &lt;/summary&gt;
      /// &lt;param name="sender"&gt;&lt;/param&gt;
      /// &lt;param name="args"&gt;&lt;/param&gt;
      private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs args)
      {
          try
          {
              // Get the exception that was thrown
              Exception exceptionThrown = (Exception)args.ExceptionObject;
  
              Console.WriteLine("Information coming from exception handler");                                
          }
          catch (Exception ex)
          {                
              Console.WriteLine(ex.ToString());                
          }
      }
  
      #endif
  
  }
  </code></pre>