title: Catching exceptions in web api - Should I use a try-catch statement?
body: <p>This is a sample <code>ApiController</code> used </p>
  
  <pre><code>[RequestExceptionFilter]
  public class RequestController : ApiController
  {
      public IHttpActionResult Post([FromBody]Request RequestDTO)
      {
          //some code over here
          throw new DTONullException(typeof(Request.Models.DTO.Request));
  </code></pre>
  
  <p>This is my <code>custom exception handler</code></p>
  
  <pre><code>public class RequestExceptionFilterAttribute : ExceptionFilterAttribute
      {
          public override void OnException(HttpActionExecutedContext context)
          { 
              if (context.Exception is DTONullException)
              {
                  context.Response = new HttpResponseMessage(HttpStatusCode.BadRequest)
                  {
                      Content = new StringContent("DTO is null"),
                      ReasonPhrase = "DTO is null",
                  };
              }
  
              base.OnException(context);
          }
      }
  </code></pre>
  
  <p>And while debugging, I get this error:</p>
  
  <p><code>An exception of type 'Request.Controllers.DTONullException' occurred in Request.dll but was not handled in user code</code></p>
  
  <p><img src="https://i.stack.imgur.com/tlUFK.png" alt="enter image description here"></p>
  
  <p>Should I use the <code>try-catch</code> syntax here ? What is the convention ?</p>
  
  <p>In all the samples I see in the internet, people just <code>throw the exception</code> but they dont seem to catch it.</p>
  
  <p>(Ofcourse, If i press <code>Run</code>, the application returns a <code>BadRequest</code> as expected but the question is should i use <code>try-catch</code> or just leave the code above as such ?)</p>