public static String exceptionStackTrace(Throwable t) {
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        try {
            t.printStackTrace(pw);
            return sw.toString();
        } finally {
            pw.close();
        }
    }
Utility class for working with exceptions.
aws-java-sdk-core/src/main/java/com/amazonaws/internal/ExceptionUtils.java