Episerver provides content editors with a lot of flexibility for configuring content. Gone are the days of having lots and lots of different templates. On my projects, I would typically have less than 20 page types and then x number of blocks. One common problem that keeps cropping up, is how to deal with block exceptions?
On some of the more content/feature heavy pages, I've had page instances that might have 100+ blocks loaded onto it. If one of those blocks error for whatever reason, the whole page falls over and the user is shown a 500 error. In the majority of situations, the better solution is to have Episerver deal with the error quietly in the background and then render the page out as you expect and in most circumstances have a very small area of a page look a bit funky or not display.
Luckily, Episerver is very customizable and allows you to hook into it pretty easily. In today's guide, we're going to go over some code that will hide all exceptions thrown by blocks for you to deal with yourself.
public class ErrorHandlingContentRenderer : IContentRenderer
private readonly MvcContentRenderer _mvcRenderer;
public CustomContentRenderer(MvcContentRenderer mvcRenderer)
_mvcRenderer = mvcRenderer;
public void Render(HtmlHelper helper, PartialRequest partialRequestHandler, IContentData contentData, TemplateModel templateModel)
mvcRenderer.Render(helper, partialRequestHandler, contentData, templateModel);
catch (Exception ex)
// Deal With It
void Render(HtmlHelper helper, PartialRequest partialRequestHandler, IContentData contentData, TemplateModel templateModel);
Software Architect, Programmer and Technologist Jon Jones is founder and CEO of London-based tech firm Digital Prompt. He has been working in the field for nearly a decade, specializing in new technologies and technical solution research in the web business. A passionate blogger by heart , speaker & consultant from England.. always on the hunt for the next challenge