获取异常详细信息,组成字符串

View Code
 1 /**  
 2      * 获取exception详情信息  
 3      *   
 4      * @param e  
 5      *            Excetipn type  
 6      * @return String type  
 7      */  
 8     public static String getExceptionDetail(Exception e) {   
 9   
10        StringBuffer msg = new StringBuffer(10);   
11  
12        if (e != null) {   
13            msg = new StringBuffer("");   
14  
15            String message = e.toString();   
16  
17            int length = e.getStackTrace().length;   
18  
19            if (length > 0) {   
20  
21                msg.append(message + "\n");   
22  
23                for (int i = 0; i < length; i++) {   
24  
25                    msg.append("\t" + e.getStackTrace()[i] + "\n");   
26  
27                }   
28            } else {   
29  
30                msg.append(message);   
31            }   
32  
33        }   
34        return msg.toString();   
35    }

当需要异常信息,把这些记入数据库日志的时候。。这个有用。

原文地址:https://www.cnblogs.com/a393060727/p/2857400.html