Gets the root cause of an Exception/Error

@param throwable The exception/error to find the root cause of.
@return The root cause of the exception, or throwable if it is the root cause.
439138
public static Throwable getRootCause(Throwable throwable) {
        if (throwable.getCause() != null)
            return getRootCause(throwable.getCause());

        return throwable;
    }
900811
public static String getExceptionMessage(Throwable exception)
    {
        StringWriter        out = new StringWriter();
        exception.printStackTrace(new PrintWriter(out));
        BufferedReader      in = new BufferedReader(new StringReader(out.toString()));
        try
        {
            StringBuilder       str = new StringBuilder();
            for(;;)
            {
                String  line = in.readLine();
                if ( line == null )
                {
                    break;
                }
                if ( str.length() > 0 )
                {
                    str.append(", ");
                }
                str.append(line);
            }
            return str.toString();
        }
        catch ( IOException e )
        {
            // ignore
        }
        return "n/a";
    }
1190304
public static Throwable getCause(Throwable thr) {
		Throwable cause = thr.getCause();
		while (cause != null && cause != thr && cause != cause.getCause() && cause.getCause() != null) {
			cause = cause.getCause();
		}
		return cause == null ? thr : cause;
	}
1213886
public static RuntimeException initCause(RuntimeException ex,
                                             Throwable cause)
    {
        if (Throwable_initCause != null) {
            Object[] args = { cause };
            try {
                Throwable_initCause.invoke(ex, args);
            } catch (Exception e) {
                // Ignore any exceptions
            }
        }
        return ex;
    }
572262
public static Throwable getUltimateCause(final Throwable throwable) {
    if (throwable.getCause() == null) {
      return throwable;
    } else {
      return getUltimateCause(throwable.getCause());
    }
  }
1188037
public <T extends Throwable> T throwing(T throwable) {
        if (instanceofLAL) {
            ((LocationAwareLogger) logger).log(THROWING_MARKER, FQCN, LocationAwareLogger.ERROR_INT, "throwing", null, throwable);
        }
        return throwable;
    }
500740
public static Exception rethrow(Throwable throwable) throws Error {
        try {
            throw throwable;
        } catch (Error error) {
            throw error;
        } catch (Exception exception) {
            return exception;
        } catch (Throwable throwable2) {
            return msg.undeclaredThrowable(throwable2);
        }
    }
460555
public static Class<?> getExceptionCallerClass(final Throwable t) {
		final StackTraceElement[] stackTrace = t.getStackTrace();
		for (final StackTraceElement stackTraceElement : stackTrace) {
			logger.debug(stackTraceElement.getClassName().concat(".").concat(stackTraceElement.getMethodName()));
		}
		return null;
	}
872374
private static RuntimeException getCause(final InvocationTargetException e) {
    final Throwable cause = e.getCause();
    if (cause instanceof RuntimeException) {
      throw (RuntimeException) cause;
    } else {
      throw new IllegalStateException(e.getCause());
    }
  }
941466
public static Throwable getNextThrowable(Throwable t) {

        Throwable nextThrowable = null;
        if (t != null) {

            // try getCause first.
            nextThrowable = t.getCause();

            if (nextThrowable == null) {
                // if getCause returns null, look for the JDBC and JCA specific chained exceptions
                // in case the resource adapter or database has not implemented getCause and initCause yet.
                if (t instanceof SQLException) {
                    nextThrowable = ((SQLException) t).getNextException();
                }

                else if (t instanceof ResourceException) {
                    nextThrowable = ((ResourceException) t).getCause(); 
                }
            }
        }
        return nextThrowable;
    }
1307573
@Override
    @CallerSideMethod public void onError(Throwable throwable) {
        if ( throwable == null )
            throw null;
        _onError(throwable);
    }
79941
private static Throwable findRootCause(Throwable t) {
        Throwable root = t;
        Throwable cause = root.getCause();
        while (cause != null) {
            root = cause;
            cause = root.getCause();
        }
        return root;
    }
1341333
private RuntimeException launderException(final Throwable throwable) {
        if (throwable instanceof RuntimeException) {
            return (RuntimeException) throwable;
        } else if (throwable instanceof Error) {
            throw (Error) throwable;
        } else {
            throw new IllegalStateException("Unchecked exception", throwable);
        }
    }
790537
public static KbRuntimeException fromThrowable(Throwable cause) {
    return (cause instanceof KbRuntimeException)
                   ? (KbRuntimeException) cause
                   : new KbRuntimeException(cause);
  }
768637
private Throwable getCause(Throwable t) {
        Throwable cause = t.getCause();
        if (t.getCause() != null) {
            return cause;
        } else {
            return t;
        }
    }
1138919
public static Throwable getRootCause(Throwable exception) {
    Assert.notNull(exception);
    return exception.getCause() == null ? exception : getRootCause(exception.getCause());
  }
548046
public void onThrowable(Throwable cause) {
        this.cause = cause;
        getSelf().tell(RequestWorkerMsgType.PROCESS_ON_EXCEPTION, getSelf());

    }