ace ace -5 years ago 207
Java Question

How to store printStackTrace into a string

How can I get the

and store it into a
I want to use the string generated by
later in my program.

I'm still new to Java so I'm not too familiar with
that I think
will be the solution. Or if you have any other ideas please let me know. Thanks

Answer Source

Something along the lines of

StringWriter errors = new StringWriter();
ex.printStackTrace(new PrintWriter(errors));
return errors.toString();

Ought to be what you need.

Relevant documentation:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download