What can i do to catch rendering exceptions in mvc? (I am using 1st version)
I started from worth case scenario - compile time error in .ascx file and here is what i discovered:
1) In debug mode, visual studio says there is unhandled exception in Controller.ExecuteCore(), InvokeAction line:
try {
string actionName = RouteData.GetRequiredString("action");
if (!ActionInvoker.InvokeAction(ControllerContext, actionName)) { // this line
HandleUnknownAction(actionName);
}
}
finally {
TempData.Save(ControllerContext, TempDataProvider);
}
2) Application.OnError is not called
3) Controller.OnError is not called
4) when I injected catch() here it is also not triggered.
5) try.. catch in masterpage doesn't triggered (althrough it present in stacktrace!)
6) try.. catch in page doesn't triggered (it also present in stacktrace!)
I was able to catch exception only when I wrapped specific RenderPartial method, like this:
<% try
{ %>
<%Html.RenderPartial("Search/" + Model.SearchCategory + "SearchList", Model); %>
<%}
catch (Exception ex)
{ %><% HttpContext.Current.Response.Redirect("/en/App/Error"); %><% } %>
And what i can do than?
- I cannot return RedirectAction because we are not in controller
- I try HttpContext.Current.Response.Redirect but it is not really working (I am having page with text: Object moved to .)