优化 ExceptionUtil 工具类
1.增加私有构造函数,此工具类不能被实例化 2.优化 getRootErrorMessage() 方法逻辑,去除不必要判断
This commit is contained in:
parent
4f5bf990bf
commit
d1a8a58552
|
|
@ -11,6 +11,9 @@ import org.apache.commons.lang3.exception.ExceptionUtils;
|
|||
*/
|
||||
public class ExceptionUtil
|
||||
{
|
||||
|
||||
private ExceptionUtil() {}
|
||||
|
||||
/**
|
||||
* 获取exception的详细错误信息。
|
||||
*/
|
||||
|
|
@ -24,16 +27,10 @@ public class ExceptionUtil
|
|||
public static String getRootErrorMessage(Exception e)
|
||||
{
|
||||
Throwable root = ExceptionUtils.getRootCause(e);
|
||||
root = (root == null ? e : root);
|
||||
if (root == null)
|
||||
if (null == root)
|
||||
{
|
||||
return "";
|
||||
return StringUtils.EMPTY;
|
||||
}
|
||||
String msg = root.getMessage();
|
||||
if (msg == null)
|
||||
{
|
||||
return "null";
|
||||
}
|
||||
return StringUtils.defaultString(msg);
|
||||
return StringUtils.defaultString(root.getMessage(), "null");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue