当前位置:   article > 正文

获取Exception的详细信息

exception获得方法

转自:http://blog.csdn.net/long95wang/article/details/8089489


方法一:

public static String getExceptionAllinformation(Exception ex){
String sOut = “”;
StackTraceElement[] trace = ex.getStackTrace();
for (StackTraceElement s : trace) {
sOut += “\tat ” + s + “\r\n”;
}
return sOut;
}


方法二:

public static String getExceptionAllinformation_01(Exception ex) {
ByteArrayOutputStream out = new ByteArrayOutputStream();
PrintStream pout = new PrintStream(out);
ex.printStackTrace(pout);
String ret = new String(out.toByteArray());
pout.close();
try {
out.close();
} catch (Exception e) {
}
return ret;
}


方法三:

  1. private static String toString_02(Throwable e){
  2. StringWriter sw = new StringWriter();
  3. PrintWriter pw = new PrintWriter(sw, true);
  4. e.printStackTrace(pw);
  5. pw.flush();
  6. sw.flush();
  7. return sw.toString();
  8. }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

转载于:https://www.cnblogs.com/ChickenTang/p/5655407.html

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/你好赵伟/article/detail/349252
推荐阅读
相关标签
  

闽ICP备14008679号