Skip to content

Commit 1465e7d

Browse files
committed
添加获取异常堆栈信息工具类
1 parent 1b9eece commit 1465e7d

File tree

1 file changed

+52
-0
lines changed
  • api-boot-project/api-boot-common/src/main/java/org/minbox/framework/api/boot/common/tools

1 file changed

+52
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright [2019] [恒宇少年 - 于起宇]
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
18+
package org.minbox.framework.api.boot.common.tools;
19+
20+
import java.io.PrintWriter;
21+
import java.io.StringWriter;
22+
23+
/**
24+
* Exception Stack Trace Tool
25+
*
26+
* @author:恒宇少年 - 于起宇
27+
* <p>
28+
* DateTime:2019-07-15 17:53
29+
* Blog:http://blog.yuqiyu.com
30+
* WebSite:http://www.jianshu.com/u/092df3f77bca
31+
* Gitee:https://gitee.com/hengboy
32+
* GitHub:https://github.com/hengboy
33+
*/
34+
public class StackTraceTools {
35+
36+
/**
37+
* Get Exception Stack Trace
38+
*
39+
* @param throwable Exception Instace
40+
* @return Stack Trace
41+
*/
42+
public static String getStackTrace(Throwable throwable) {
43+
StringWriter sw = new StringWriter();
44+
PrintWriter pw = new PrintWriter(sw);
45+
try {
46+
throwable.printStackTrace(pw);
47+
return sw.toString();
48+
} finally {
49+
pw.close();
50+
}
51+
}
52+
}

0 commit comments

Comments
 (0)