use of cn.bran.japid.compiler.JapidCompilationException in project japid42 by branaway.
the class JapidRenderer method handleException.
public static RenderResult handleException(Throwable e) throws RuntimeException {
if (!presentErrorInHtml)
if (e instanceof RuntimeException)
throw (RuntimeException) e;
else
throw new RuntimeException(e);
// if (Play.mode == Mode.PROD)
// throw new RuntimeException(e);
//
Class<? extends JapidTemplateBaseWithoutPlay> rendererClass = getErrorRendererClass();
if (e instanceof JapidTemplateException) {
RenderResult rr = RenderInvokerUtils.invokeRender(rendererClass, (JapidTemplateException) e);
return (rr);
}
if (e instanceof RuntimeException && e.getCause() != null)
e = e.getCause();
if (e instanceof JapidCompilationException) {
JapidCompilationException jce = (JapidCompilationException) e;
JapidTemplateException te = JapidTemplateException.from(jce);
RenderResult rr = RenderInvokerUtils.invokeRender(rendererClass, te);
return (rr);
}
e.printStackTrace();
// find the latest japidviews exception or the controller that caused
// the exception
StackTraceElement[] stackTrace = e.getStackTrace();
for (StackTraceElement ele : stackTrace) {
String className = ele.getClassName();
if (className.startsWith("japidviews")) {
int lineNumber = ele.getLineNumber();
RendererClass applicationClass = japidClasses.get(className);
if (applicationClass != null) {
// let's get the line of problem
int oriLineNumber = applicationClass.mapJavaLineToJapidScriptLine(lineNumber);
if (oriLineNumber > 0) {
if (rendererClass != null) {
String path = applicationClass.getScriptPath();
JapidTemplateException te = new JapidTemplateException("Japid Error", path + "(" + oriLineNumber + "): " + e.getClass().getName() + ": " + e.getMessage(), oriLineNumber, path, applicationClass.getJapidSourceCode());
RenderResult rr = RenderInvokerUtils.invokeRender(rendererClass, te);
return (rr);
}
}
}
} else if (className.startsWith("controllers.")) {
if (e instanceof RuntimeException)
throw (RuntimeException) e;
else
throw new RuntimeException(e);
}
}
JapidTemplateException te = new JapidTemplateException(e);
RenderResult rr = RenderInvokerUtils.invokeRender(rendererClass, te);
return rr;
// if (e instanceof RuntimeException)
// throw (RuntimeException) e;
// else
// throw new RuntimeException(e);
}
Aggregations