开发者

HandleError is not redirecting to the view after the exception has occurred!

For some reason the view ErrorPage is not being call even 开发者_如何学运维through an exception of type "InvalidOperationExcepion" is being thrown.

 [HandleError(View = "ErrorPage", ExceptionType = typeof(InvalidOperationException))]
        public ActionResult Request(RequestIn requestin)
        {           


            try
            {
                var emailService = new EmailServices();


               // exception is thrown from some WCF service!       
                var error = emailService.SendMail("to@someting.com", "from@someting.com", "Request", message, message);
            }
            catch (Exception ex)
            {

            }



            ViewData["Message"] = "Email has been sent!";     

            return View("Confirmation"); 
        }

Any ideas!


That's because you handled the exception. Remove the try/catch block.


@frennky is correct in saying it doesn't catch it because you handled the exception. If you still need that try catch you could always rethrow the exception in the catch block. That way you can perform any logging or other cleanup before it is handled by the HandleError attribute.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜