@Override public void processExcption(BeetlException ex, Writer writer) { ErrorInfo error = new ErrorInfo(ex); int line = error.getErrorTokenLine(); StringBuilder sb = new StringBuilder(">>") .append(error.getType()) .append(":") .append(error.getErrorTokenText()) .append(" 位于") .append(line) .append("行") .append(" 资源:") .append(getResourceName(ex.resourceId)); ; println(writer, sb.toString()); if (error.getErrorCode().equals(BeetlException.TEMPLATE_LOAD_ERROR)) { printCause(error, writer); return; } ResourceLoader resLoader = ex.gt.getResourceLoader(); // 潜在问题,此时可能得到是一个新的模板,不过可能性很小,忽略! String content = null; ; try { Resource res = resLoader.getResource(ex.resourceId); // 显示前后三行的内容 int[] range = this.getRange(line); content = res.getContent(range[0], range[1]); if (content != null) { String[] strs = content.split(ex.cr); int lineNumber = range[0]; for (int i = 0; i < strs.length; i++) { print(writer, "" + lineNumber); print(writer, "|"); println(writer, strs[i]); lineNumber++; } } } catch (IOException e) { // ingore } printCause(error, writer); }
protected void printCause(ErrorInfo error, Writer writer) { Throwable t = error.getCause(); if (t != null) { printThrowable(writer, t); } }