Java Utililty Methods Exception Message

List of utility methods to do Exception Message

Description

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

Method

Exceptionexception(Throwable e)
exception
if (e instanceof Exception) {
    return (Exception) e;
} else {
    return new Exception(e);
Stringexception(Throwable t)
Constructs a pretty one line version of a Throwable .
StackTraceElement[] trace = t.getStackTrace();
return t.getClass().getSimpleName() + " : " + t.getMessage()
        + ((trace.length > 0)
                ? " @ " + t.getStackTrace()[0].getClassName() + ":" + t.getStackTrace()[0].getLineNumber()
                : "");
StringexceptionMessage(Object... strings)
exception Message
StringBuilder msg = new StringBuilder();
msg.append(strings[0]).append(System.lineSeparator());
msg.append("Additional exception info:").append(System.lineSeparator());
for (int i = 1; i < strings.length; i++) {
    msg.append("\t").append(strings[i]).append(System.lineSeparator());
msg.append("Stacktrace:");
return msg.toString();
...
StringexceptionMessage(Throwable e)
exception Message
StringBuilder buffer = new StringBuilder();
buffer.append(extractMessage(e));
if (e.getCause() != null) {
    buffer.append(" [cause: ").append(extractMessage(e.getCause())).append("]");
return buffer.toString();
StringexceptionSimpleDesc(final Exception e)
exception Simple Desc
StringBuffer sb = new StringBuffer();
if (e != null) {
    sb.append(e.toString());
    StackTraceElement[] stackTrace = e.getStackTrace();
    if (stackTrace != null && stackTrace.length > 0) {
        StackTraceElement elment = stackTrace[0];
        sb.append(", ");
        sb.append(elment.toString());
...
StringexceptionStackTrace(Exception ex)
exception Stack Trace
StringBuffer buffer = new StringBuffer();
for (StackTraceElement element : ex.getStackTrace()) {
    buffer.append(element.toString());
    buffer.append("\n");
return buffer.toString();