JAVA: How to capture java exception stack trace in String

Many a times you might need to capture java exception (stack trace) in string, here is a small code snippet to do that:
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw, true);
String stackTrace = sw.getBuffer().toString();
This same method can be used to capture string from other streams and assign it to a String/StringBuffer.


Popular posts from this blog

Sling Authentication

CQ Development - OSGi bundles and Components

Create an AEM (CQ) project using Maven

Multiple log files using log4j appender