@Test public void testGetExceptionStackTrace() throws Exception { RuntimeException exception = new RuntimeException("foo"); exception.initCause(new RuntimeException(new IOException("BOOM"))); String stackTrace = new ErrorBean().getExceptionStackTrace(exception); assertTrue(Stream.of(stackTrace) .filter(s -> s.contains("BOOM")) .findAny() .isPresent()); assertTrue(stackTrace.contains("foo")); }
public String getExceptionStackTrace(Throwable t) { if (null == t) { return ""; } LOGGER.log(Level.SEVERE, "Unexpected error condition", t); StringWriter sw = new StringWriter(); try (PrintWriter w = new PrintWriter(sw)) { t.printStackTrace(w); } return sw.toString(); }
ErrorBean { public String getExceptionStackTrace(Throwable t) { if (null == t) { return ""; } LOGGER.log(Level.SEVERE, "Unexpected error condition", t); StringWriter sw = new StringWriter(); try (PrintWriter w = new PrintWriter(sw)) { t.printStackTrace(w); } return sw.toString(); } }
ErrorBean { public String getExceptionStackTrace(Throwable t) { if (null == t) { return ""; } LOGGER.log(Level.SEVERE, "Unexpected error condition", t); StringWriter sw = new StringWriter(); try (PrintWriter w = new PrintWriter(sw)) { t.printStackTrace(w); } return sw.toString(); }  }
ErrorBean { public String getExceptionStackTrace(Throwable t) { if (null == t) { return ""; } LOGGER.log(Level.SEVERE, "Unexpected error condition", t); StringWriter sw = new StringWriter(); try (PrintWriter w = new PrintWriter(sw)) { t.printStackTrace(w); } return sw.toString(); }  String getExceptionStackTrace(Throwable t); }
ErrorBean { public String getExceptionStackTrace(Throwable t) { if (null == t) { return ""; } LOGGER.log(Level.SEVERE, "Unexpected error condition", t); StringWriter sw = new StringWriter(); try (PrintWriter w = new PrintWriter(sw)) { t.printStackTrace(w); } return sw.toString(); }  String getExceptionStackTrace(Throwable t);  }