From 3c4fee1db116c11d4f04727cfe076d7c94daeaf2 Mon Sep 17 00:00:00 2001 From: yanzhaofeige <yanzhaofeige@qq.com> Date: Mon, 30 Sep 2024 12:10:57 +0800 Subject: [PATCH] init --- cpzidc-common/src/main/java/com/odcc/cpzidc/common/utils/ExceptionUtil.java | 39 +++++++++++++++++++++++++++++++++++++++ 1 files changed, 39 insertions(+), 0 deletions(-) diff --git a/cpzidc-common/src/main/java/com/odcc/cpzidc/common/utils/ExceptionUtil.java b/cpzidc-common/src/main/java/com/odcc/cpzidc/common/utils/ExceptionUtil.java new file mode 100644 index 0000000..b657b96 --- /dev/null +++ b/cpzidc-common/src/main/java/com/odcc/cpzidc/common/utils/ExceptionUtil.java @@ -0,0 +1,39 @@ +package com.odcc.cpzidc.common.utils; + +import java.io.PrintWriter; +import java.io.StringWriter; +import org.apache.commons.lang3.exception.ExceptionUtils; + +/** + * 错误信息处理类。 + * + * @author ruoyi + */ +public class ExceptionUtil +{ + /** + * 获取exception的详细错误信息。 + */ + public static String getExceptionMessage(Throwable e) + { + StringWriter sw = new StringWriter(); + e.printStackTrace(new PrintWriter(sw, true)); + return sw.toString(); + } + + public static String getRootErrorMessage(Exception e) + { + Throwable root = ExceptionUtils.getRootCause(e); + root = (root == null ? e : root); + if (root == null) + { + return ""; + } + String msg = root.getMessage(); + if (msg == null) + { + return "null"; + } + return StringUtils.defaultString(msg); + } +} -- Gitblit v1.9.3