package com.vci.common.exception; public class VciExceptionTool { /** * 获取异常的首行显示信息 * @param e * @return */ public static String getExceptionStr(Throwable e) { if (e == null) { return ""; } String str = ""; if (e.getCause() != null) { str = e.getCause().toString(); } else { str = e.toString(); } if (str == null) { str = ""; } return str; } /** * 获取异常的所有信息 * @param e * @return */ public static String getExceptionDetail(Throwable e) { if (e == null) { return ""; } StringBuffer msg = new StringBuffer(""); msg.append(getStackTraceDetail(e)); if (e.getCause() != null) { msg.append(getStackTraceDetail(e.getCause())); } return msg.toString(); } private static String getStackTraceDetail(Throwable e) { StringBuffer msg = new StringBuffer(""); String message = e.toString(); int length = e.getStackTrace().length; if (length > 0) { msg.append(message + "\n"); for (int i = 0; i < length; i++) { msg.append("\t" + e.getStackTrace()[i] + "\n"); } } else { msg.append(message); } return msg.toString(); } }