Java: Convert Exception StackTrace to a String

/**
 * Convert stack trace to a string
 * @param ex
 * @return
 */
public static String stacktraceToString(Exception ex) {
    StringWriter sw = new StringWriter();
    ex.printStackTrace(new PrintWriter(sw));
    String exceptionAsString = sw.toString();
    return exceptionAsString;
}

Werbung



comments powered by Disqus

Copyright Dunkel & Iwer GbR | Datenschutzerklärung | Impressum