[英]Printing Stack Trace to textarea
我正在使用以下代码将堆栈跟踪打印到JTextArea
:
try
{
throw new IOException();
}
catch(IOException e)
{
e.printStackTrace(pw);
ta1.append(sw.toString());
}
pw.flush();
sw.flush();
try
{
throw new SQLException();
}
catch(SQLException e)
{
e.printStackTrace(pw);
ta1.append(sw.toString());
}
它打印出2个IOException
跟踪和1个SQLExeption
跟踪。 为什么不将字符串编写器冲洗掉?
我想要1个IOException
跟踪和1个SQLExeption
跟踪。
请提出正确的方法。
StringWriter
的flush
方法什么都不做! flush
方法仅与java.io.Writer
兼容。
StringWriter
来源:
/**
* Flush the stream.
*/
public void flush() {
}
然后PrintWriter
调用StringWriter
flush
方法...
PrintWriter
来源:
/**
* Flushes the stream.
* @see #checkError()
*/
public void flush() {
try {
synchronized (lock) {
ensureOpen();
out.flush();
}
}
catch (IOException x) {
trouble = true;
}
}
因此,如果要清除pw
和sw
,则不应使用flush
方法。 您需要创建一个新的。
见:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.