How to handle 500 server errors in Umbraco

I just want a custom error page when a server error occurs - I've tried endless combinations of suggestions that I've found on google but nothing even begins to get me there.



Essentially, I have some error handling routines in my surface controllers where I want to log the error & then throw the exception so that somewhere down the line a 500 response code is returned & a custom error page is displayed.



                try
{
repository.AddShoppingCartItem(sci);
}
catch(Exception e)
{
Log.Error("whatever...");
throw;
}


Then in my web.config I've tried



   <customErrors mode="On" defaultRedirect="error500">
</customErrors>


and



   <customErrors mode="On" defaultRedirect="umbraco/surface/error500surface">
</customErrors>


(where the 1st version uses a regular controller & the second a surface controller)



Neither do anything.



I've also added this line as others have suggested but it makes no difference:



What I get is my normal layout page getting rendered along with this message:



Error loading Partial View script (file: ~/Views/MacroPartials/Addcart.cshtml)



what I want to happen is for a custom error page to be displayed instead.



Reading all the stuff on google, I'm completely confused as to whether I need to configure Umbraco to handle these errors or whether it's a pure MVC approach. I get the impression that 404 errors are done through umbraco but 500 errors need to be a pure MVC approach. Don't know if anyone can confirm this. Either way, something up the chain is swallowing my throw statement & I don't know what it is.



I've also tried



return new HttpStatusCodeResult(500);



in place of the throw & that just gets me a nasty IIS error page.



Any help would be most appreciated as this is driving me nuts.



Answers

500 errors are server errors and no different in Umbraco than in regular IIS:




This is a server error and can only be solved by website admin who has access to files and the web-server. There can be one of/or multiple reasons to get this error. One has to track down the issue and handle accordingly.




http://www.codeproject.com/Articles/545054/HTTPplus-plus-e-plusInternalplusserverplus



More info:
http://serverfault.com/questions/407954/how-to-diagnose-a-500-internal-server-error-on-iis-7-5-when-nothing-is-written-t



Edit: apparently you may be able to enable custom errors like so:

http://helpnotes.vpasp.com/kb/611-General-hosting-questions/1089-How-to-Turn-Off-Friendly-Error-in-IIS-7xx/



Edit2: This may be of interest as well:

http://benfoster.io/blog/aspnet-mvc-custom-error-pages