I trying to check if an exception has been raised by an action with the filterContext.Exception below:
public class Test : ActionFilterAttribute
[...]
public override void OnActionExecuted(ActionExecutedContext filterContext)
{
if (filterContext.Exception != null)
{
continue;
}
}
in controller:
[Test]
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Login(Usuarios usuario)
{
try
{
throw new Exception();
}
catch
{
}
}
The filterContext.Exception is always null.I can't catch this inf开发者_StackOverflowormation here.
Any ideias?
That's because the exception never escapes the action method since it gets caught as soon as you throw it. I'm surprised that your code compiles since you don't have a return statement. Anyway, try this action method:
[Test]
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Login(Usuarios usuario)
{
throw new Exception();
}
精彩评论