the simplest way to change the result of Throwable.getStackTrace() to a string that depicts the stack trace is:
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
String sStackTrace = sw.toString(); // stack trace as a string
This program records within the Throwable object data from the code above about the current state of the stack frames for the current thread.
If the stack trace of the Throwable is not writable, calling this process has no effect.
To read more about it click here.