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.
精彩评论