private String getStackTrace(final Throwable error) {
    if (error != null) {
      try (final StringWriter sw = new StringWriter();
           final PrintWriter pw = new PrintWriter(sw)) {
        pw.println();
        error.printStackTrace(pw);
        return sw.toString();
      } catch (final IOException ex) {
        // should never happen
        throw new RuntimeException("Unexpected error while logging stack trace", ex);
      }
    }
    return "";
  }
private String getStackTrace ( final Throwable error ) { if ( error != null ) { try ( final StringWriter sw = new StringWriter ( ) ; final PrintWriter pw = new PrintWriter ( sw ) ) { pw . println ( ) ; error . printStackTrace ( pw ) ; return sw . toString ( ) ; } catch ( final IOException ex ) { throw new RuntimeException ( "Unexpected error while logging stack trace" , ex ) ; } } return "" ; }
@return a string that contains stack trace of a given exception.
if `error` is null, return an empty string.