2017  Kodetalk | Feedback | Privacy Policy | Terms | About
userimage

How to convert java exception stacktrace to string format

my requirement is i want to convert the java exception

e.printStackTrace()

to string format

userimage

try below to convert a java exception stacktrace to string

StringWriter stringWriter = new StringWriter();
PrintWriter printWriter = new PrintWriter(stringWriter);
e.printStackTrace(printWriter);

from here you can try

stringWriter.toString()

to get the string of the exception catched.

Answer is