我在java中有这个代码:
try{
//some code here.. .
} catch (Exception e) {
message = "Error occurred : " + e.getCause();
throw e;
}
在 freemarker 中:
<table width="1238" cellpadding="0" cellspacing="0" align="center">
<tr>
<td align="center" class="Fontmost">
<p><@ww.property value = "message"/> <!-- message from java -->
<br />
<br />
</p>
</td>
</tr>
</table>
我正在维护的应用程序的最后一个开发人员使用 e.getCause()
而不是 e.getMessage()
。目前,我们只需要异常消息,因为 e.getCause()
会在页面中打印整个堆栈跟踪。有没有办法只修改freemarker代码就可以只显示异常信息?因为我们的java代码中所有的类和模块都使用e.getCause()
,所以我们有40个模块需要改变,如果我们将 e.getCause()
修改为 e.getMessage()
。
感谢你们提供的任何帮助。
提前致谢。
最佳答案
我建议您将异常本身添加到模型中(例如,以“异常”名称)并在模板中使用它:exception.message
或 exception.cause.message
code>,具体取决于您想要的异常。
关于java - 如何仅显示错误消息,而不显示 java 和 freemarker 中的完整堆栈跟踪?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6172657/