code: public static String buildStackTraceString(final Throwable ex) {
          final StringBuilder context = new StringBuilder(ex.toString());
          final StringWriter sw = new StringWriter();
          ex.printStackTrace(new PrintWriter(sw, true));
          context.append('\n');
          context.append(sw.toString());
  
          return context.toString();
      }
docs: finds out the stack trace up to where the exception was thrown.
  
  @return String that contains the stack trace