title: Throw exception ActionFilterAttribute OnActionExecuting
body: <p>I want to throw a exception in the ActionFilterAttribute like this:</p>
  
  <pre><code>public override void OnActionExecuting(ActionExecutingContext filterContext) {
      base.OnActionExecuting(filterContext);
  
      if (!_controller.HasRoleIndex()) {
          throw new Exception(Resources.BackOffice.lblErrorPermission);
      }
  }
  </code></pre>
  
  <p>I want it like this, because I want to execute this code in some ajax request, and when the user dosen't have permissions, send a exception and then showing a message.</p>
  
  <p>I have the code of showing the message in the exception implemented, and it works for exeptions in other places of the aplication, but when an exception is thrown in the OnActionExecuting of the ActionFilterAttribute, a unhandled exception in the application, and what I get in the view is a Server Error.</p>
  
  <p>How can I handle the exception, without redirecting to another page? I only want to throw the exception, no show a 404 error page.</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>To put things in context: I have a web page with some ajax calls, I wanted the ajax calls to have a behavior in case that an error ocurred while the call was made so I have something like this in all my ajaxs:</p>
  
  <pre><code> $.ajax({
   ...
   error: function (e, o, errorText) { AlertMessages.SetErrorMessageAndShow(errorText); },
   ...
  });
  </code></pre>
  
  <p>This code shows a modal window with a friendly user message with the cause of the error:
  Session expired. Bad email adress, etc.</p>
  
  <p>I want to use the same code for validation. And with validation I was thinking of use ActionFilterAttribute.</p>
  
  <p>But I can't get how to send and exception from the OnActionExecuting.</p>
  
  <p>Is this possible? or i have to return a specific Json and then in the javascript act acording the json returned?</p>