Skip to content

Instantly share code, notes, and snippets.

@bluerabbit
Created February 1, 2013 02:30
Show Gist options
  • Select an option

  • Save bluerabbit/4688711 to your computer and use it in GitHub Desktop.

Select an option

Save bluerabbit/4688711 to your computer and use it in GitHub Desktop.
ExceptionのStackTraceを文字列で取得する
public static String getStackTrace(Throwable e) {
StringWriter sw = null;
PrintWriter pw = null;
try {
sw = new StringWriter();
pw = new PrintWriter(sw);
e.printStackTrace(pw);
return sw.toString();
} finally {
try {
if (sw != null) {
sw.flush();
sw.close();
}
if (pw != null) {
pw.flush();
pw.close();
}
} catch (IOException ignore) {
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment