I am catching exceptions to provide better information for the logs to make debugging easier in production. I was wondering if this code follows best practices as I'm not really handling the error but just logging extra information. I was also considering creating a custom RazorException
, and throwing that instead. What do you think?
public string ParseFile(string templatePath, object model = null)
{
//some code was removed for clarity
try
{
ITemplate template = _templateService.Resolve(templatePath, model);
ExecuteContext context = new ExecuteContext();
content = template.Run(context);
}
catch (TemplateCompilationException tcex) {
_logger.Fatal("Razor parse failed: check for synthax error", tcex);
throw;
}
catch (InvalidOperationException ex) {
_logger.Fatal("Razor parse failed: trying to compile layout on it's own", ex);
throw;
}
catch (Exception ex) {
_logger.Fatal("Razor parse failed", ex);
throw;
}
return content;
}