java通过Throwable的printStackTrace方法将异常信息保存到字符串中
/** * 将异常信息转化成字符串 * @param t * @return * @throws IOException */ private static String exception(Throwable t) throws IOException{ if(t == null) return null; ByteArrayOutputStream baos = new ByteArrayOutputStream(); try{ t.printstacktrace(new PrintStream(baos)); }finally{ baos.close(); } return baos.toString(); }
标签:java,return,printStackTrace,Throwable,字符串,baos From: https://www.cnblogs.com/nextgg/p/16711385.html