title: Unable to throw exception on ajax call from controller
body: <p>I want throw exception on client side on ajax call but I have no status code.
  what I do to handle error on ajax error function.</p>
  
  <p>When I call ajax function it generate some exception on SaveAccount Controller and I handle it through HandleExceptionAttribute and I return json at last but it hit on success function insted of error what is the problem. 
  please help. Thanks</p>
  
  <pre><code>public class HandleExceptionAttribute : HandleErrorAttribute
  {
      public override void OnException(ExceptionContext filterContext)
      {
          if (filterContext.HttpContext.Request.IsAjaxRequest() &amp;&amp; filterContext.Exception != null)
          {
              filterContext.Result = new JsonResult
              {
                  JsonRequestBehavior = JsonRequestBehavior.AllowGet,
                  Data = new
                  {
                      filterContext.Exception.Message,
                  }
              };
              filterContext.ExceptionHandled = true;
          }
          else
          {
              base.OnException(filterContext);
          }
      }
  }
  
  [HandleExceptionAttribute]
      [AllowAnonymous]
      [HttpPost]
      public ActionResult SaveAccount(AccountViewModel vm)
      {
          try
          {
              using (var context = new AdvisorFinancialEntities())
              {
                  ..........
                  context.SaveChanges();
              }
  
          }
          catch (Exception ex)
          {
              Exception e = new Exception("Failed to save account");
              e.Data.Add("Accounts", "SaveAccount");
  
              throw e;
          }
          return Json(true, JsonRequestBehavior.AllowGet);
      }
  </code></pre>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code> $.ajax({
                  url: '@Url.Action("SaveAccount", "Accounts")',
                  cache: false,
                  type: 'POST',
                  contentType: 'application/json',
                  data: jsonData,
                  success: function (result) {
                      ShowToastMessage("Account has been saved successfully", "Success",true);      
                      Reset();
                  },
                  error: function (xhr, textStatus, errorThrown) {
                      var err = JSON.parse(xhr.responseText);
                      ShowToastMessage(err.Message, "Save Account",false);      
  
                  }
              });</code></pre>
  </div>
  </div>
  </p>