public static String getStackTrace(Throwable throwable, long maxLines) {
    StringWriter writer = new StringWriter();
    PrintWriter pw = new PrintWriter(writer, true);
    throwable.printStackTrace(pw);
    String[] lines = writer.toString().split(NEWLINE);
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < Math.min(lines.length, maxLines); i++) {
      if (i > 0) {
        sb.append(NEWLINE);
      }
      sb.append(lines[i]);
    }
    return sb.toString();
  }
@Test
  public void testExceptionStackTrace() {
    try {
      throw new Exception("error happened!!");
    } catch (Exception e) {
      assertEquals(0, ExceptionHelper.getStackTrace(e, 0).length());
      assertTrue(
          ExceptionHelper.getStackTrace(e, 1).startsWith("java.lang.Exception: error happened!!"));
      assertTrue(ExceptionHelper.getStackTrace(e, 2000).length() > 100);
    }
  }