Showing posts with label Stacktrace for the Java. Show all posts
Showing posts with label Stacktrace for the Java. Show all posts

Sunday, August 28, 2011

Stacktrace for the Java


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();