获取Java Exception异常详细信息,以便保存

来源:互联网 发布:广西广电网络多少钱 编辑:程序博客网 时间:2024/05/29 17:16
public static String getExceptionAllInfo(Exception ex) {        ByteArrayOutputStream out = null;        PrintStream pout = null;        String ret = "";        try {        out = new ByteArrayOutputStream();        pout = new PrintStream(out);        ex.printStackTrace(pout);        ret = new String(out.toByteArray());        out.close();        }catch(Exception e){        return ex.getMessage();        }finally{        if(pout!=null){        pout.close();        }        }        return ret;}

1 0