public static String exceptionChainToString(Throwable t){
  StringWriter sw=new StringWriter();
  PrintWriter pw=new PrintWriter(sw,true);
  while (t != null) {
    t.printStackTrace(pw);
    t=t.getCause();
  }
  pw.flush();
  sw.flush();
  return sw.toString();
}

public static String exceptionChainToString ( Throwable t ) { StringWriter sw = new StringWriter ( ) ; PrintWriter pw = new PrintWriter ( sw , true ) ; while ( t != null ) { t . printStackTrace ( pw ) ; t = t . getCause ( ) ; } pw . flush ( ) ; sw . flush ( ) ; return sw . toString ( ) ; }
prints full exception stack trace , from top to root cause , into a string .
