Java convert stacktrace to string for logging to a database

Well in my Java project I wanted to log the exception stacktrace to a database file, so there comes the need to convert it to a string. Here is how to do it ...
public static String getMyStackTrace(Exception e) {
       
        StringWriter stringWriter = new StringWriter();
        PrintWriter printWriter = new PrintWriter(stringWriter, true);
        e.printStackTrace(printWriter);
        return stringWriter.toString();
  
    }

No comments:

Post a Comment

NO JUNK, Please try to keep this clean and related to the topic at hand.
Comments are for users to ask questions, collaborate or improve on existing.