private static String stackToString(Throwable exception) {
    String result = "";
    if (exception.getMessage() == null) result = exception.toString();
    else result = exception.getMessage() + ": ";
    
    if (exception.getStackTrace() == null) result = result + " <== stacktrace is null";
    else {
      StackTraceElement[] stackTrace = exception.getStackTrace();
      for (int i = 0; i < stackTrace.length; i++) {
        result = result +
                " <== " + stackTrace[i].getClassName() + "." + stackTrace[i].getMethodName() +
                " (" + stackTrace[i].getFileName() + ": " + stackTrace[i].getLineNumber() + ")";
      }
    }
    return result;
  }