开发者

How to show the error message only, not the full stack trace in java and freemarker?

开发者 https://www.devze.com 2023-03-09 08:10 出处:网络
I have this code in java : try{ //some code here.. . } catch (Exception e) { message = \"Error occurred : \" + e.getCause();

I have this code in java :

try{
   //some code here.. .
} catch (Exception e) {
   message = "Error occurred : " + e.getCause();
   throw e;
}

And in freemarker :

<table width="1238" cellpadding="0" cellspacing="0" align="center">
  <tr>
    <td align="center" class="Fontmost">
      <p><@ww.property value = "message"/> <!-- message from java -->
    &nbsp;
    <br />
    <br />
      </p>
    </td>
  </tr>
</table>

The last developer of the application that i'm maintaining uses e.getCa开发者_运维问答use() instead of e.getMessage() . For now, we need only the exception message because e.getCause() prints the whole stack trace in the page. Is there any way to show only the exception message by just modifying the freemarker code?, because all the classes and modules in our java code uses e.getCause(), we have 40 modules to change if we modify e.getCause() to e.getMessage().

I appreciate any help coming from you guys.

Thanks in advance.


I suggest you add the exception itself to the model (e.g. under the name "exception") and use it in the template: exception.message or exception.cause.message, depending on the exception you want.


Will

message.message

help? This accesses the getMessage() function.


Unfortunately, message is of type string! If it was message = e.getCause(); instead of message = "Error occurred : " + e.getCause(); , Daniel's answer would be the solution.

0

精彩评论

暂无评论...
验证码 换一张
取 消