String (Throwable thrown) { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); thrown.printStackTrace(pw); String[] lines = StringUtil.splitByLines(sw.toString()); int maxStackSize = 1024; int maxExtraSize = 256; if (lines.length > maxStackSize + maxExtraSize) { String[] res = new String[maxStackSize + maxExtraSize + 1]; System.arraycopy(lines, 0, res, 0, maxStackSize); res[maxStackSize] = "\t..."; System.arraycopy(lines, lines.length - maxExtraSize, res, maxStackSize + 1, maxExtraSize); return StringUtil.join(res, LINE_SEPARATOR); } return sw.toString(); }