Skip to content

Instantly share code, notes, and snippets.

@e2kaneko
Created October 8, 2018 04:53
Show Gist options
  • Save e2kaneko/be42f650e48938a9c8e775a7d3de111f to your computer and use it in GitHub Desktop.
Save e2kaneko/be42f650e48938a9c8e775a7d3de111f to your computer and use it in GitHub Desktop.
例外トレースを文字列に変換
/**
* 例外メッセージのトレース情報を文字列に変換します
* @param exception 例外オブジェクト
* @return 例外トレース文字列
*/
protected String getTraceString(Exception exception) {
StringWriter stringWriter = new StringWriter();
PrintWriter printWriter = new PrintWriter(stringWriter);
exception.printStackTrace(printWriter);
printWriter.flush();
return stringWriter.toString();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment