码迷,mamicode.com
首页 > 其他好文 > 详细

输出异常信息

时间:2018-10-28 12:51:43      阅读:148      评论:0      收藏:0      [点我收藏+]

标签:nbsp   out   xtend   刷新   public   ceo   row   writer   继承   

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则能获取异常信息到字符串中

输出异常信息

标签:nbsp   out   xtend   刷新   public   ceo   row   writer   继承   

原文地址:https://www.cnblogs.com/dayanjing/p/9865024.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!