Java Utililty Methods Exception to String

List of utility methods to do Exception to String

Description

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

Method

StringgetExceptionMessage(Exception e)
Retrieve exception stack message
final StringBuilder sb = new StringBuilder();
e.printStackTrace(new PrintStream(new OutputStream() {
    @Override
    public void write(int b) throws IOException {
        sb.append((char) b);
}));
return sb.toString();
...
StringgetExceptionMessage(Exception ex)
get Exception Message
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
ex.printStackTrace(pw);
return sw.toString();
StringgetExceptionMessage(Exception ex)
get Exception Message
return getExceptionMessage(ex, true);
StringgetExceptionMsg(Exception ex)
Get Exception msg.
StringBuilder sb = new StringBuilder();
if (ex != null) {
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    ex.printStackTrace(pw);
    sb.append(sw.toString());
return sb.toString();
...
StringgetExceptionName(IOException ex)
get Exception Name
return ex.getClass().getSimpleName();
StringgetExceptionStackTrace(Exception exception)
get Exception Stack Trace
java.io.OutputStream out = new java.io.ByteArrayOutputStream();
java.io.PrintStream ps = new java.io.PrintStream(out, true);
exception.printStackTrace(ps);
String str = out.toString();
return str;
StringgetExceptionStackTraceAsString(final Exception exception)
get Exception Stack Trace As String
final StringWriter sw = new StringWriter();
exception.printStackTrace(new PrintWriter(sw));
return sw.toString();