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 information 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: