In Umbraco, if there is a razor macro on a page, and that razor macro throws an exception, the page is still displayed, but it shows “Error loading macro xyz.cshtml” where the macro would have been.
I’d like to redirect to a custom/friendly error page whenever that happens, but I can’t find any information on how to do it. Is it possible?
I’ve tried setting the <customErrors> tag as usual, but it doesn’t work.
Within each razor script, you could surround your code with a try/catch and then redirect if an error is caught:
But rather than redirecting the user, you could also just catch the error and then do nothing. It depends on your needs.