简体   繁体   中英

Is it possible in Java's MessageFormat to receive a stack trace?

Code:

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

Eg 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.

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM