title: Handling WCF Rest Service exceptions only in one place
body: <p>I'm developing an WCF Rest service that I'm going to host on an IIS.</p>
  
  <p>Now I'm implementing Service Contract, and I see that I'm repeating the same code on all of my methods when I'm trying to handle exceptions.</p>
  
  <p>This is one of my Service Contract method:</p>
  
  <pre><code>public void DeleteMessage(string message_id)
  {
      int messageId;
      OutgoingWebResponseContext ctx =
          WebOperationContext.Current.OutgoingResponse;
  
      if ((message_id == null) || (!Int32.TryParse(message_id, out messageId)) || (messageId &lt; 1))
      {
          ctx.StatusCode = System.Net.HttpStatusCode.BadRequest;
          ctx.StatusDescription = "message_id parameter is not valid";
          throw new ArgumentException("DeleteMessage: message_id is not valid", "message_id");
      }
  
      try
      {
          using (var context = new AdnLineContext())
          {
              Message message = new Message() { MessageId = messageId };
  
              context.Entry(message).State = EntityState.Deleted;
              context.SaveChanges();
  
              ctx.StatusCode = System.Net.HttpStatusCode.OK;
          }
      }
      catch (Exception ex)
      {
          ctx.StatusCode = System.Net.HttpStatusCode.InternalServerError;
          ctx.StatusDescription = ex.Message;
          ctx.SuppressEntityBody = true;
      }
  }
  </code></pre>
  
  <p>On all of my methods I could throw an <code>ArgumentException</code> or an <code>Exception</code>, and manage them with return a <code>HTTP STATUS CODE</code>.</p>
  
  <p><strong>Is there any way to catch that exceptions globally?</strong></p>