提交 | 用户 | 时间
|
a6de49
|
1 |
/** |
H |
2 |
* Copyright (c) 2018 人人开源 All rights reserved. |
|
3 |
* |
|
4 |
* https://www.renren.io |
|
5 |
* |
|
6 |
* 版权所有,侵权必究! |
|
7 |
*/ |
|
8 |
|
|
9 |
package com.iailab.framework.common.exception; |
|
10 |
|
|
11 |
import java.io.IOException; |
|
12 |
import java.io.PrintWriter; |
|
13 |
import java.io.StringWriter; |
|
14 |
|
|
15 |
/** |
|
16 |
* Exception工具类 |
|
17 |
* |
|
18 |
* @author Mark sunlightcs@gmail.com |
|
19 |
*/ |
|
20 |
public class ExceptionUtils { |
|
21 |
|
|
22 |
/** |
|
23 |
* 获取异常信息 |
|
24 |
* @param ex 异常 |
|
25 |
* @return 返回异常信息 |
|
26 |
*/ |
|
27 |
public static String getErrorStackTrace(Exception ex){ |
|
28 |
StringWriter sw = null; |
|
29 |
PrintWriter pw = null; |
|
30 |
try { |
|
31 |
sw = new StringWriter(); |
|
32 |
pw = new PrintWriter(sw, true); |
|
33 |
ex.printStackTrace(pw); |
|
34 |
}finally { |
|
35 |
try { |
|
36 |
if(pw != null) { |
|
37 |
pw.close(); |
|
38 |
} |
|
39 |
} catch (Exception e) { |
|
40 |
|
|
41 |
} |
|
42 |
try { |
|
43 |
if(sw != null) { |
|
44 |
sw.close(); |
|
45 |
} |
|
46 |
} catch (IOException e) { |
|
47 |
|
|
48 |
} |
|
49 |
} |
|
50 |
|
|
51 |
return sw.toString(); |
|
52 |
} |
|
53 |
} |