Print the stack trace of an exception

后端 未结 9 1154
有刺的猬
有刺的猬 2020-12-05 03:31

How do I print the stack trace of an exception to a stream other than stderr? One way I found is to use getStackTrace() and print the entire list to the stream.

相关标签:
9条回答
  • 2020-12-05 04:20

    For the android dev minimalists: Log.getStackTraceString(exception)

    0 讨论(0)
  • 2020-12-05 04:27

    See javadoc

    out = some stream ...
    try
    {
    }
    catch ( Exception cause )
    {
          cause . printStrackTrace ( new PrintStream ( out ) ) ;
    }
    
    0 讨论(0)
  • 2020-12-05 04:34

    The Throwable class provides two methods named printStackTrace, one that accepts a PrintWriter and one that takes in a PrintStream, that outputs the stack trace to the given stream. Consider using one of these.

    0 讨论(0)
提交回复
热议问题