将Java异常信息保存到字符串中

来源:互联网 发布:python 3.5.2打开 编辑:程序博客网 时间:2024/05/27 00:48
/** * 将异常信息转化成字符串 * @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();}


                                             
0 0