title: Global Exception Handler for all types of the Exceptions in WebApi2
body: <p>I'm working on Exception Handling on WebApi and i need to send error messages to my Clients through adding <code>HttpStatusCode</code> and <code>ErrorBody</code>. </p>
  
  <p>i have tried and i have found some useful solutions, Like <code>ExceptionFilters</code>, <code>HttpResponseMessage</code> and some Global exception handlers but i didn't deep in them because i am in feasibility study.</p>
  
  <p>some of them, Like <code>ExceptionFilters</code> runs before/after getting the Exceptions and they were useful for Logging purpose. but all of them just throw my running code into a runtime exception.</p>
  
  <p>I spent a day to find, how can i collect and get rid of VisualStudio runtime errors, when i run an <code>throw new ...</code> expression; but i couldn't reach to what i was searching for.</p>
  
  <p>When i choose <code>HttpResponseMessage</code> as return types of my ActionMethods, it's pretty easy way to make an error and send it back to the client request. 
  but when i want to choose another way, for example :</p>
  
  <pre><code> public User GetAllUsers()
   {
       ... //Some Codes
       {
          throw new HttpResponseException(HttpStatusCode.Accepted);
       }
       else { ... }
   }
  </code></pre>
  
  <p>it just drive me to a runtime error (i think, it's just a warning because i only need to press F5 to get rid of this server side Bump :) )  and after all i will see my generated error message on Client-Side application.</p>
  
  <p>I don't want to use <code>HttpResponseMessage</code> as output type of my <code>ActionMethods</code>, because I'm responsible to develop both Front-End and Back-End and it takes a wearisome check to see "What is the type of this ActionMethod ?" </p>
  
  <p>how can i do this work ?</p>