There are two ways you can do this.
The first is to use the getStackTrace() method, which returns an array
of StackTraceElement. You can loop through that array and and push
the contents into your log. The advantage to this is that you can
just log the parts of the stack trace you are interested in.
The second way is to create a StringWriter class to capture the output
from the Exception using the printStackTrace(PrintWriter) method.
Here is some sample code:
StringWriter sWriter = new StringWriter();
e.printStackTrace(new PrintWriter(sWriter));
System.out.println(sWriter.getBuffer().toString()) ;
-Nathan
na******@informatica.com (Naresh Agarwal) wrote in message news:<2b**************************@posting.google. com>...
Hi
Is there a way to copy the stack trace in a string, which is obtained
via printStackTrace function of Exception object.
Essentially I want to log the stack trace in case of any exception in
a log file.
thanks,
Naresh