Writer out = new StringWriter();
PrintWriter s = new PrintWriter(out); // 创建不带自动行刷新的新 PrintWriter。
exception.printStackTrace(s); //将异常信息放入out中
msg = out.toString();

 

exceoption的printStackTrace(PrintWriter p) 从Throwable 继承来(public class Exception extends Throwable )

将异常输出到p中。参数只有PrintWriter类型,所以将out转成PrintWriter,用StringWriter的toString则能获取异常信息到字符串中

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-21
  • 2021-09-19
  • 2021-08-22
猜你喜欢
  • 2021-05-09
  • 2021-10-26
  • 2021-06-21
  • 2021-11-20
  • 2021-12-08
  • 2021-10-01
  • 2022-01-06
相关资源
相似解决方案