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