code: protected void printStackTrace(final PrintWriter printWriter, final Throwable throwable) {
          throwable.printStackTrace(printWriter);
          Throwable cause = throwable.getCause();
          while (cause != null) {
              if (cause instanceof SQLException) {
                  final SQLException nextException = ((SQLException) cause).getNextException();
                  if (nextException != null) {
                      printWriter.print("Next exception: ");
                      printStackTrace(printWriter, nextException);
                  }
              }
              cause = cause.getCause();
          }
      }
docs: Prints stacktraces to the string writer, and investigates the throwable
  hierarchy to check if there's any {@link SQLException}s which also has
  "next" exceptions.
  
  @param printWriter
  @param throwable