0

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?

1 Answer 1

3

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(); 
} 
Sign up to request clarification or add additional context in comments.

1 Comment

@Kirov yes it does, as asked by the OP in reference to MVC2. Unless you are referencing a completely different scenario, in which case I don't know what you are talking about.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.