Java如何将Exception.printStackTrace()转换为String输出
2012-01-13 15:03
751 查看
原文地址:/article/4183826.html
package com.test1; import java.io.PrintWriter; import java.io.StringWriter; public class T010 { /** * @param args */ public static void main(String[] args) { try { String[] arr = {"111", "222"}; arr[2] = "fff"; } catch (Exception e) { String info = getErrorInfoFromException(e); System.out.println(info); } } public static String getErrorInfoFromException(Exception e) { try { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); e.printStackTrace(pw); return "\r\n" + sw.toString() + "\r\n"; } catch (Exception e2) { return "bad getErrorInfoFromException"; } } } 控制台上输出的消息如下所示: java.lang.ArrayIndexOutOfBoundsException: 2 at com.test1.T010.main(T010.java:14)
相关文章推荐
- Java如何将Exception.printStackTrace()转换为String输出
- Java如何将Exception.printStackTrace()转换为String输出
- Exception.printStackTrace()转换为String输出
- java中exception的printStackTrace()输出内容转成字符串
- java中exception的printStackTrace()输出内容转成字符串
- java中exception的printStackTrace()输出内容转成字符串
- 使用日志框架如何输出printStackTrace()的堆栈信息
- 【技术】Java入门:e.printStackTrace()和System.out输出顺序混乱的问题
- 使用log4j的时候如何输出printStackTrace()的堆栈信息
- 使用log4j的时候如何输出printStackTrace()的堆栈信息
- java 获取e.printStackTrace() 的具体信息,赋值给String 变量 并返回
- 使用log4j的时候如何输出printStackTrace()的堆栈信息
- Java 输出 printStackTrace 堆栈信息
- JAVA Catch中异常信息的输出 System.out.println(e) e.printStackTrace()
- ART如何实现Exception.printStackTrace
- 怎样把e.printStackTrace()这个异常保存到一个字符串变量中如:String str;
- 得到java异常printStackTrace的详细信息
- java.nio.BufferOverflowException. Check the Eclipse log for stack trace.
- 如何将int转换成String 在java中
- 如何解决异常:java.lang.NumberFormatException: For input string: "null"