|
Java异常堆栈字符串输出 public class ExceptionTrans {
/**
* 异常信息转换为字符串
*
* @param t 异常对象
* @return
*/
public static String ex2String(Throwable t) {
StringWriter sw = new StringWriter();
t.printStackTrace(new PrintWriter(sw, true));
return sw.getBuffer().toString();
}
public static void main(String[] args) {
String ex = null;
try {
int a = 0;
a = a / a;
if (true) {
throw new CordException("test");
}
} catch (Exception e) {
e.printStackTrace();
ex = ex2String(e);
System.out.println("------------------------");
}
System.out.printf(ex);
}
} |
----------------------------
原文链接:https://blog.51cto.com/lavasoft/2129490
作者:熔岩
程序猿的技术大观园:www.javathinker.net
[这个贴子最后由 admin 在 2020-03-14 13:53:49 重新编辑]
|
|