title: Application_Error in global.asax not catching errors in WebAPI
body: <p>For a project I am working on, one of the things we're implementing is something that we have code for in some of my teams older ASP.NET and MVC projects - an <code>Application_Error</code> exception catcher that dispatches an email to the development team with the exception experience and most relevant details.</p>
  
  <p>Here's how it looks:</p>
  
  <p><strong>Global.asax:</strong></p>
  
  <pre><code>protected void Application_Error(object sender, EventArgs e)
  {
      Exception ex = Server.GetLastError();
      string path = "N/A";
      if (sender is HttpApplication)
          path = ((HttpApplication) sender).Request.Url.PathAndQuery;
  
      string args = string.Format("&lt;b&gt;Path:&lt;/b&gt; {0}", path);
  
      // Custom code that generates an HTML-formatted exception dump
      string message = Email.GenerateExceptionMessage(ex, args);
  
      // Custom code that sends an email to the dev team.
      Email.SendUnexpectedErrorMessage("Some App", message);
  }
  </code></pre>
  
  <p>One "minor" problem, though - when I intentionally have a part of the code throw an exception in order to test this mechanism...</p>
  
  <pre><code>public static void GetMuffinsByTopping(string topping)
  {
      throw new Exception("Test Exception!", new Exception("Test Inner Exception!!!"));
  
      // Actual repository code is unreachable while this test code is there
  }
  </code></pre>
  
  <p>The front-end JavaScript is immediately intercepting an HTTP 500 request, but the global.asax.cs code noted above is not being reached (I set a breakpoint on the first executing line of the method.)</p>
  
  <p><strong>Question:</strong> In what way can I get the "old" <code>Application_Error</code> handler to dispatch error emails, so that our team's developers can more easily debug our application?</p>