private String getFormattedStackTrace(StackTraceElement[] stacktrace) { StringBuilder sb = new StringBuilder(); for (StackTraceElement element : stacktrace) { sb.append(element.toString()).append("\n"); } return sb.toString(); }
private void logTrace(StringBuilder builder, Throwable e) { Throwable parent = e; String indent = " "; while (parent != null) { if (parent == e) { builder.append(indent).append("Trace:").append("\n"); } else { builder .append(indent) .append("Caused By: (") .append(parent.getClass().getSimpleName()) .append(")") .append("\n"); builder .append(indent) .append(" ") .append("[") .append(parent.getMessage()) .append("]") .append("\n"); } for (StackTraceElement ele : e.getStackTrace()) { builder.append(indent).append(" ").append(ele.toString()).append("\n"); } indent += " "; parent = parent.getCause(); } }
/** * Shows an alert dialog for when an exception occurs. * * @param e the exception to show * @param title the title of the dialog */ public static void debug(Exception e, String title) { e.printStackTrace(); String text = "<i>" + e.toString() + "</i><br>"; // add stack trace for (StackTraceElement ste : e.getStackTrace()) { text += ste.toString() + "<br>"; } text += "<br><b>Please take a screenshot and email it to <u>[email protected]</u>.</b>"; showDialog(null, "<html>Sorry! Cabra has encountered an error. Details:<br><br>" + text, title); }