What would be the best way to convert Stack Trace from Exception
to String
?
What would be the best way to convert Stack Trace from Exception
to String
?
I came across this need and doing a web search I found this great solution in SOen, which allows you to get this important information as String
, without having to import other libraries:
try {
} catch (Exception e) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
sw.toString(); //Aqui obtenho a String
}