StringWriter stringWriter = new StringWriter(); PrintWriter printWriter = new PrintWriter(stringWriter); ex.printStackTrace(printWriter); String stackTrace = stringWriter.toString(); or : if you are already using apache commons lang in your project, use the getStackTrace method in the ExceptionUtils class org.apache.commons.lang.exception.ExceptionUtils.getStackTrace(Throwable)