tips/JAVA/Throwable printStackTrace() の結果を文字列として取り出す(追記) のバックアップ(No.1)


tips/JAVA/Throwable printStackTrace() の結果を文字列として取り出す(2 of 2)


Throwable printStackTrace() の結果を文字列として取り出す(追記)

以前書いた

tips/JAVA/Throwable printStackTrace() の結果を文字列として取り出す(1 of 2)

tips/JAVA/Throwable printStackTrace() の結果を文字列として取り出す(2 of 2)

について、PipedReader/Writer を用いて実現しようとしていましたが、 もっと簡便な方法がありました。。。

Throwable#printStackTrace(PrintWriter) の引数に渡す PrintWriter に StringWriter を使えばよいようです。 StringWriter なんて便利なクラスがあったんですね。。。

ちなみにマルチスレッドでの挙動は確認していません。