0

Code:

String message = MessageFormat.format("error {0}",e);

E.g. message:

     java.text.ParseException: Unparseable date: "sdf sf sa dg "

I need to receive all the stack trace, like:

java.text.ParseException: Unparseable date: "sdf sf sa dg "
at java.text.DateFormat.parse(Unknown Source)
 ................

Is this possible ? Thanks.

Raul Rene
  • 10,014
  • 9
  • 53
  • 75
user710818
  • 23,228
  • 58
  • 149
  • 207
  • 1
    See [this answer](http://stackoverflow.com/questions/1149703/stacktrace-to-string-in-java) which talks about how to convert an exception to String. – Thomas Jul 04 '12 at 15:56

1 Answers1

3

You can use this method to capture the stacktrace in a String

public String getStackTrace(Throwable t) {
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    t.printStackTrace(pw);
    pw.flush();
    return sw.toString();
}

EDIT: the SO article linked by Thomas is also a very good read!

Community
  • 1
  • 1
fvu
  • 32,488
  • 6
  • 61
  • 79