Android Throwable to String Convert getExceptionMessage(Throwable ex)

Here you can find the source of getExceptionMessage(Throwable ex)

Description

get Exception Message

Declaration

public static String getExceptionMessage(Throwable ex) 

Method Source Code

//package com.java2s;

public class Main {
    public static String getExceptionMessage(Throwable ex) {
        StringBuilder sb = new StringBuilder(ex.getClass().getSimpleName())
                .append(":");
        if (ex.getMessage() != null) {
            sb.append(ex.getMessage()).append("\n");
        }//  ww w.  j av a  2 s  .  c o  m

        for (StackTraceElement element : ex.getStackTrace()) {
            sb.append(element.toString()).append("-")
                    .append(element.getLineNumber()).append("\n");
        }

        if (ex.getCause() != null) {
            String inner = getExceptionMessage(ex.getCause());
            sb.append(inner);
        }

        sb.append("\n");
        return sb.toString();
    }
}

Related

  1. stringify(Throwable t)
  2. getExceptionMessage(Throwable e)
  3. exceptionToString(Throwable t)
  4. failException(String message, Throwable got)