Java Exception.printStackTrace()をStringに変換
551 ワード
自分で叶えて
apache.commons.langパッケージの使用
String str = org.apache.commons.lang3.exception.ExceptionUtils.getStackTrace(Throwable);
public static String getErrorInfoFromException(Exception e) {
try {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
return "\r
" + sw.toString() + "\r
";
} catch (Exception e2) {
return "bad getErrorInfoFromException";
}
}
apache.commons.langパッケージの使用
String str = org.apache.commons.lang3.exception.ExceptionUtils.getStackTrace(Throwable);