1

i am trying to simulate exception management in ASP MVC,

Here is what i have:

public JsonResult callit()
{
        throw new HttpException(400, "Bad Request");
}

and then i try to call it like this:

$.ajax({
        type: 'GET',
        url: '@Url.Action("callit", "rat", new { area = "test" })',
        cache: 'false',
        error: function (request, status, error) {
            alert(request.responseText);
        }
});

But my application keeps on stopping when the exception is thrown and my error is not being triggered unless i stop the program. What should i do?

Carlos Miguel Colanta
  • 2,685
  • 3
  • 31
  • 49

1 Answers1

3

Rather than throwing an exception, return a HttpStatusCodeResult and change you method to ActionResult

public ActionResult callit() // or public HttpStatusCodeResult callit()
{  
    return new HttpStatusCodeResult(400, "Bad Request");
}