List of utility methods to do Stacktrace
String | stackTrace2String(Throwable e) make exception stack trace become string StringBuffer sb = new StringBuffer(); sb.append(e.toString()).append("\r\n"); StackTraceElement[] traces = e.getStackTrace(); for (StackTraceElement trace : traces) { sb.append(trace.toString()).append("\r\n"); return sb.toString(); |
boolean | stackTraceApproved(StackTraceElement elt, String[] approved) stack Trace Approved String className = elt.getClassName(); for (int i = 0; i < approved.length; i++) { String s = approved[i]; if (className.startsWith(s)) return true; return false; |
String | stackTraceAsString(Throwable t) stack Trace As String StringBuilder sb = new StringBuilder(); sb.append(t.getClass().getName()).append(": ").append(t.getMessage()); for (StackTraceElement e : t.getStackTrace()) { sb.append("\n"); sb.append(e.toString()); return sb.toString(); |
boolean | stackTraceContainsCause(Throwable throwable, Class extends Throwable> searchedCause) Check if the stack trace of provided exception contains a given cause. Throwable t = throwable; while ((t = t.getCause()) != null) { if (searchedCause.isAssignableFrom(t.getClass())) { return true; return false; |
String | stackTraceElementToString(StackTraceElement element) stack Trace Element To String String methodName = element.getMethodName(); if (methodName == null || UNKNOWN.equals(methodName)) return null; String frame = " at "; String className = element.getClassName(); if (className != null && !UNKNOWN.equals(className)) frame += className + "."; frame += methodName + "("; ... |
String | stackTraceElementWithLinenumber(StackTraceElement stackTraceElement) Generates a string from trace for the current class with linenumber. if (null != stackTraceElement) { return stackTraceElement.getClassName() + LINE_NUMBER_SEPARATOR + stackTraceElement.getLineNumber(); } else { return "Internal ERROR stackTraceElement should not be null"; |
String | stackTraceElementWithLinenumberAsString(StackTraceElement stackTraceElement) stack Trace Element With Linenumber As String if (null != stackTraceElement) { return stackTraceElement.getClassName() + LINE_NUMBER_SEPARATOR + stackTraceElement.getLineNumber(); } else { return "Internal ERROR stackTraceElement should not be null"; |
boolean | stackTraceEquals(StackTraceElement[] ta1, StackTraceElement[] ta2) Compares two stack traces and checks if they are equal if (ta1 == ta2) { return true; if (ta1.length == ta2.length) { for (int i = 0, lnLength = ta1.length; i < lnLength; i++) { if (!equals(ta1[i], ta2[i])) { return false; return true; return false; |
String | stackTraceGenerate() stack Trace Generate StackTraceElement[] steArr = Thread.currentThread().getStackTrace(); String ret = ""; for (StackTraceElement ste : steArr) { ret += ste.toString() + "\n"; return ret; |