How can I properly handle exceptions thrown from controllers in ASP.NET MVC? The HandleError attribute seems to handle exceptions thrown by the MVC framework, rather than exceptions thrown by my own code.
Using this web.config
<customErrors mode="On"> <error statusCode="401" redirect="/Errors/Http401" /> </customErrors>
with the following code
namespace MvcApplication1.Controllers { [HandleError] public class HomeController : Controller { public ActionResult Index() {
doesn't lead to what i was hoping for. Instead, I get a generic ASP.NET error page telling me to modify my web.config to see the actual error information. However, if instead of throwing an exception, I return the wrong view, I get the page /Shared/Views/Error.aspx:
return View("DoesNotExist");
Throwing exceptions in the controller, as I did above, seems to get around all the functionality of HandleError , so what is the correct way to create error pages and how do I fit in well with the MVC framework?
exception asp.net-mvc
Adrian Anttila May 01 '09 at 4:58 p.m. 2009-05-01 16:58
source share