use of ninja.exceptions.RenderingException in project ninja by ninjaframework.
the class TemplateEngineFreemarker method throwRenderingException.
public void throwRenderingException(Context context, Result result, Exception cause, String knownTemplateSourcePath) {
// a more useful ParseException
if (cause instanceof IOException && cause.getCause() != null && cause.getCause() instanceof ParseException) {
cause = (ParseException) cause.getCause();
}
if (cause instanceof TemplateNotFoundException) {
// inner cause will be better to display
throw new RenderingException(cause.getMessage(), cause, result, "FreeMarker template not found", knownTemplateSourcePath, -1);
} else if (cause instanceof TemplateException) {
TemplateException te = (TemplateException) cause;
String templateSourcePath = te.getTemplateSourceName();
if (templateSourcePath == null) {
templateSourcePath = knownTemplateSourcePath;
}
throw new RenderingException(cause.getMessage(), cause, result, "FreeMarker render exception", templateSourcePath, te.getLineNumber());
} else if (cause instanceof ParseException) {
ParseException pe = (ParseException) cause;
String templateSourcePath = pe.getTemplateName();
if (templateSourcePath == null) {
templateSourcePath = knownTemplateSourcePath;
}
throw new RenderingException(cause.getMessage(), cause, result, "FreeMarker parser exception", templateSourcePath, pe.getLineNumber());
}
// fallback to throwing generic rendering exception
throw new RenderingException(cause.getMessage(), cause, result, knownTemplateSourcePath, -1);
}
Aggregations