title: SignalR, Owin and exception handling
body: <p>I've developed a sample SignalR application based on ASP.NET 4.5 &amp; Owin, and I've hosted that app on IIS 7.5.</p>
  
  <p>Everything is working fine, but how can I handle exceptions in Owin?</p>
  
  <p>Consider the following code:</p>
  
  <pre><code>[HubName("SampleHub")]
  public class SampleHub : Hub
  {
      public SampleHub()
      {
          throw new InvalidOperationException("?!");
      }
  }
  </code></pre>
  
  <p>This exception won't call <code>Application_Error</code> (and this is my problem).</p>
  
  <p>Where can I get all exceptions from Owin for logging and debugging purposes similarly to <code>Application_Error</code>?</p>
  
  <p>I'm not interested in something like this:</p>
  
  <pre><code>app.UseErrorPage(new ErrorPageOptions()
  {
      ShowCookies = true,
      ShowEnvironment = true,
      ShowExceptionDetails = true,
      ShowHeaders = true,
      ShowQuery = true,
      ShowSourceCode = true
  });
  </code></pre>
  
  <p>This is totally useless for advanced scenarios, something like ASP.NET Web API and ASP.NET MVC.</p>
  
  <p>Action filters with OnException method for override purposes is much better.</p>