final Writer result = new StringWriter();
final PrintWriter printWriter = new PrintWriter(result);
e.printStackTrace( printWriter);
String stacktrace = result.toString();
Report += stacktrace;
Report += "\n";
// If the exception was thrown in a background thread inside
// AsyncTask, then the actual exception can be found with getCause
Throwable cause = e.getCause();
if(cause!=null){
Report += "Cause : \n"; Report += "======= \n";
}
while (cause != null) {
cause.printStackTrace( printWriter);
Report += result.toString();
cause = cause.getCause();
}
printWriter.close();