Java Tips: 将Exception的stacktrace信息转成字符串

StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);

        try {
                getException().printStackTrace(pw);
                exceptionStack = sw.toString();
        }
        finally {
            try {
                    sw.close();
                    pw.close();
            } catch (IOException e) {
                    // ignore
            }
        }

你可能感兴趣的:(java)