Java获取异常堆栈信息
方法一:
public static String getStackTrace(Throwable t) { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); try { t.printStackTrace(pw); return sw.toString(); } finally { pw.close(); } }
方法二:
org.apache.commons.lang3.exception.ExceptionUtils.getStackTrace(e);