捕捉Java的异常Stacktrace

来源:互联网 发布:java的可变参数 编辑:程序博客网 时间:2024/06/04 17:54
    public static String exceptionToString(Throwable th) {        String stTrace = "";        StringWriter sout = null;        PrintWriter out = null;        try {            sout = new StringWriter();            out = new PrintWriter(sout);            th.printStackTrace(out);            stTrace = sout.toString();        } catch (Exception ex) {        } finally {            try {                if (out != null)                    out.close();                if (sout != null)                    sout.close();            } catch (IOException ex) {            }        }        return stTrace;    }
0 0
原创粉丝点击