优化 ExceptionUtil 工具类

1.增加私有构造函数,此工具类不能被实例化
2.优化 getRootErrorMessage() 方法逻辑,去除不必要判断
This commit is contained in:
EFT 2024-06-14 23:09:08 +08:00
parent 4f5bf990bf
commit d1a8a58552
1 changed files with 6 additions and 9 deletions

View File

@ -11,6 +11,9 @@ import org.apache.commons.lang3.exception.ExceptionUtils;
*/ */
public class ExceptionUtil public class ExceptionUtil
{ {
private ExceptionUtil() {}
/** /**
* 获取exception的详细错误信息 * 获取exception的详细错误信息
*/ */
@ -24,16 +27,10 @@ public class ExceptionUtil
public static String getRootErrorMessage(Exception e) public static String getRootErrorMessage(Exception e)
{ {
Throwable root = ExceptionUtils.getRootCause(e); Throwable root = ExceptionUtils.getRootCause(e);
root = (root == null ? e : root); if (null == root)
if (root == null)
{ {
return ""; return StringUtils.EMPTY;
} }
String msg = root.getMessage(); return StringUtils.defaultString(root.getMessage(), "null");
if (msg == null)
{
return "null";
}
return StringUtils.defaultString(msg);
} }
} }