gpt4 book ai didi

java - Throwable getMessage() 的奇怪输出

转载 作者:行者123 更新时间:2023-12-04 06:57:08 27 4
gpt4 key购买 nike

嗨,我有下面的伪代码抛出这样的异常

throw new MyException("Bad thing happened","com.stuff.errorCode");

其中 MyException 扩展了 Exception 类。以下是我处理异常的方式
 ActionMessages errors = new ActionMessages();
if(ex.getErrorCode() != null && !"".equals(ex.getErrorCode()))
error = new ActionMessage(ex.getErrorCode()); // com.stuff.errorCode is the errorCode
else
error = new ActionMessage(ex.getMessage()); //"Bad thing happened" is error message
errors.add(ActionMessages.GLOBAL_MESSAGE, error);
//errors.add(Globals.MESSAGE_KEY, error );
saveErrors( requ, errors );
return (mapping.findForward(nextScreen));

现在在用户屏幕上,消息显示为

???en_US.Bad thing happened???



我正在使用 Struts 1.2.4,我正在研究它的源代码,但任何指针都将不胜感激。

最佳答案

避免 ActionMessage试图将您的文字信息解释为关键用途 this constructor :

error = new ActionMessage(ex.getMessage(), false);
boolean参数指定是否 String参数将被解释为要查找的代码( true )或文本消息( false )。

关于java - Throwable getMessage() 的奇怪输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2432587/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com