Java Utililty Methods Exception Format

List of utility methods to do Exception Format

Description

The list of methods to do Exception Format are organized into topic(s).

Method

StringfmtError(Exception e)
fmt Error
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
try {
    e.printStackTrace(pw);
    pw.flush();
} finally {
    pw.close();
sw.flush();
return e.getMessage() + "\n" + sw.toString();
StringformatException(final Exception e)
Formats the given exception in a multiline error message with all causes.
final StringBuilder sb = new StringBuilder();
Throwable t = e;
while (t != null) {
    sb.append(t.getMessage()).append("\n");
    t = t.getCause();
return sb.toString();
StringformatException(Throwable ex)

Returns a formatted string in the java style exception format.

StringBuilder sb = new StringBuilder();
sb.append(ex.getMessage());
sb.append("\n");
StackTraceElement[] trace = ex.getStackTrace();
for (int i = 0; i < trace.length; i++) {
    sb.append("\t");
    sb.append(trace[i]);
    sb.append("\n");
...
StringformatException(Throwable exception)
Formatea una excepcion y las excepciones padre.
StringBuilder buffer = new StringBuilder();
formatException(exception, buffer);
return buffer.toString();
StringformatException(Throwable th)
Format the information from a Throwable as string, retaining the type and its message.
return "[" + th.getClass().getSimpleName() + "]: " + th.getMessage();
StringformatExceptionMsg(String msg)
formats a message that will be displayed in a dialog, so it's not longer than 80 symbols in each line
msg = msg.replace("\n", "");
if (msg.length() > 80) {
    String result = "";
    for (int i = 0; i < msg.length(); i = i + 80) {
        int end = i + 80;
        if (msg.length() < i + 80)
            end = msg.length();
        String s = msg.substring(i, end);
...
StringformatJavaException(Exception e)
format Java Exception
return e.getClass().getSimpleName() + " - " + e.getMessage();
StringformatLogMessage(long id, Throwable exception)
format Log Message
return String.format("Error handling a request: %016x", id);
StringformatMessage(Exception e)
format Message
String msg = e.getMessage();
Throwable cause = e.getCause();
if (cause != null)
    msg = msg + "\nCause: " + cause.getMessage();
return msg;
StringformatStackTrace(Exception error)
format Stack Trace
final StringBuffer br = new StringBuffer();
StackTraceElement[] elem = error.getStackTrace();
for (int i = 0; i < elem.length; i++)
    br.append(elem[i].toString() + "\n");
return br.toString();