class ExceptionExt {

    public static String toMessageChain(Throwable error) {
        StringBuilder sb = new StringBuilder();
        Throwable current = error;
        while (current != null) {
            String message = current.getMessage() != null ? current.getMessage() : "<no_message>";
            sb.append('(').append(current.getClass().getSimpleName()).append(')').append(' ').append(message);
            if (current.getCause() != null) {
                sb.append(" -CAUSED BY-> ");
            }
            current = current.getCause();
        }
        return sb.toString();
    }

}