首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

将java错误信息stackTrace转换成字符串

2012-12-24 
将java异常信息stackTrace转换成字符串public static void main(String[] args) {List l new ArrayList(

将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();


}
}

热点排行