title: Generating custom errors for jquery.ajax()
body: <p>Lets assume that i have the following method in my httphandler (.ashx):</p>
  
  <pre><code>private void Foo()
  {
      try
      {
          throw new Exception("blah");
      }
      catch(Exception e)
      {
          HttpContext.Current.Response.Write(
              serializer.Serialize(new AjaxError(e)));
      }
  }
  
  [Serializable]
  public class AjaxError
  {
      public string Message { get; set; }
      public string InnerException { get; set; }
      public string StackTrace { get; set; }
  
      public AjaxError(Exception e)
      {
          if (e != null)
          {
              this.Message = e.Message;
              this.StackTrace = e.StackTrace;
              this.InnerException = e.InnerException != null ? 
                  e.InnerException.Message : null;
  
  
              HttpContext.Current.Response.StatusDescription = "CustomError";
          }
  
      }
  }
  </code></pre>
  
  <p>When i make an <code>$.ajax()</code> call to the method, I will end up in the <code>success</code> callback, regardless if something goes wrong back-end and I end up in the <code>catch</code> block.</p>
  
  <p>I've extended the ajax method a bit to normalise the error handling, so regardless if it's a "jquery" error (parse error etc) or my custom error, i will end up in the error callback.</p>
  
  <p>Now, what I would like to know is, should i add something like</p>
  
  <pre><code>HttpContext.Current.Response.StatusCode = 500;
  </code></pre>
  
  <p>to end up in jQuerys error handler, or should i handle my</p>
  
  <pre><code>HttpContext.Current.Response.StatusDescription = "CustomError";
  </code></pre>
  
  <p>on the jqXHR object, and assume its an error when its there?</p>
  
  <p>Let me know if something is unclear.</p>