打印异常的堆栈跟踪 [英] Print the stack trace of an exception
本文介绍了打印异常的堆栈跟踪的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将异常的堆栈跟踪打印到除stderr以外的流?我发现一种方法是使用getStackTrace()并将整个列表打印到流中。
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.
推荐答案
Throwable.printStackTrace(..)
可以采用 PrintWriter
或 PrintStream
参数: p>
Throwable.printStackTrace(..)
can take a PrintWriter
or PrintStream
argument:
} catch (Exception ex) {
ex.printStackTrace(new PrintStream(yourOutputStream));
}
那就是说,考虑使用一个记录器界面,如 SLF4J 与日志记录实现,如 LOGBack 或 log4j 。
That said, consider using a logger interface like SLF4J with an logging implementation like LOGBack or log4j.
这篇关于打印异常的堆栈跟踪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文