@Test @Ignore public void testStackTraceToString() { try { int i = 1 / 0; } catch (Exception e) { System.out.println(ExceptionUtil.stackTraceToString(e, "com.opslab")); System.out.println(ExceptionUtil.stackTraceToString(e)); } }
public static String stackTraceToString(Throwable e, String packageName) { StringWriter sw = new StringWriter(); e.printStackTrace(new PrintWriter(sw, true)); String str = sw.toString(); if (packageName == null) { return str; } String[] arrs = str.split("\n"); StringBuffer sbuf = new StringBuffer(); sbuf.append(arrs[0] + "\n"); for (int i = 0; i < arrs.length; i++) { String temp = arrs[i]; if (temp != null && temp.indexOf(packageName) > 0) { sbuf.append(temp + "\n"); } } return sbuf.toString(); }
ExceptionUtil { public static String stackTraceToString(Throwable e, String packageName) { StringWriter sw = new StringWriter(); e.printStackTrace(new PrintWriter(sw, true)); String str = sw.toString(); if (packageName == null) { return str; } String[] arrs = str.split("\n"); StringBuffer sbuf = new StringBuffer(); sbuf.append(arrs[0] + "\n"); for (int i = 0; i < arrs.length; i++) { String temp = arrs[i]; if (temp != null && temp.indexOf(packageName) > 0) { sbuf.append(temp + "\n"); } } return sbuf.toString(); } }
ExceptionUtil { public static String stackTraceToString(Throwable e, String packageName) { StringWriter sw = new StringWriter(); e.printStackTrace(new PrintWriter(sw, true)); String str = sw.toString(); if (packageName == null) { return str; } String[] arrs = str.split("\n"); StringBuffer sbuf = new StringBuffer(); sbuf.append(arrs[0] + "\n"); for (int i = 0; i < arrs.length; i++) { String temp = arrs[i]; if (temp != null && temp.indexOf(packageName) > 0) { sbuf.append(temp + "\n"); } } return sbuf.toString(); }  }
ExceptionUtil { public static String stackTraceToString(Throwable e, String packageName) { StringWriter sw = new StringWriter(); e.printStackTrace(new PrintWriter(sw, true)); String str = sw.toString(); if (packageName == null) { return str; } String[] arrs = str.split("\n"); StringBuffer sbuf = new StringBuffer(); sbuf.append(arrs[0] + "\n"); for (int i = 0; i < arrs.length; i++) { String temp = arrs[i]; if (temp != null && temp.indexOf(packageName) > 0) { sbuf.append(temp + "\n"); } } return sbuf.toString(); }  static String stackTraceToString(Throwable e, String packageName); static String stackTraceToString(Throwable e); }
ExceptionUtil { public static String stackTraceToString(Throwable e, String packageName) { StringWriter sw = new StringWriter(); e.printStackTrace(new PrintWriter(sw, true)); String str = sw.toString(); if (packageName == null) { return str; } String[] arrs = str.split("\n"); StringBuffer sbuf = new StringBuffer(); sbuf.append(arrs[0] + "\n"); for (int i = 0; i < arrs.length; i++) { String temp = arrs[i]; if (temp != null && temp.indexOf(packageName) > 0) { sbuf.append(temp + "\n"); } } return sbuf.toString(); }  static String stackTraceToString(Throwable e, String packageName); static String stackTraceToString(Throwable e);  }