wujian
2024-02-22 268beb4ebc1e5b8d4ad715b71cd64a0944073a87
提交 | 用户 | 时间
268beb 1 package com.jcdm.common.utils;
W 2
3 import java.io.PrintWriter;
4 import java.io.StringWriter;
5 import org.apache.commons.lang3.exception.ExceptionUtils;
6
7 /**
8  * 错误信息处理类。
9  *
10  * @author jc
11  */
12 public class ExceptionUtil
13 {
14     /**
15      * 获取exception的详细错误信息。
16      */
17     public static String getExceptionMessage(Throwable e)
18     {
19         StringWriter sw = new StringWriter();
20         e.printStackTrace(new PrintWriter(sw, true));
21         return sw.toString();
22     }
23
24     public static String getRootErrorMessage(Exception e)
25     {
26         Throwable root = ExceptionUtils.getRootCause(e);
27         root = (root == null ? e : root);
28         if (root == null)
29         {
30             return "";
31         }
32         String msg = root.getMessage();
33         if (msg == null)
34         {
35             return "null";
36         }
37         return StringUtils.defaultString(msg);
38     }
39 }