将java异常信息stackTrace转换成字符串


public static void main(String[] args) {

List l = new ArrayList();
try {
l.get(9);
} catch (Exception e) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);

System.out.println(sw.toString()); // stack trace as a string
    e.printStackTrace();


}
}

你可能感兴趣的:(java)