code: public static StringBuilder formatException(Throwable exception,
  												StringBuilder buffer) {
  
  //			ByteArrayOutputStream escribe = new ByteArrayOutputStream();
  //			PrintStream print = new PrintStream(escribe);
  //			exception.printStackTrace(print);
  //			String prpr= escribe.toString();
  //	
  		
  		StringBuilder ret;
  		
  		if (exception == null) {
  			ret=buffer;
  			
  		} else {
  			buffer.append(exception.getClass().getName());
  			buffer.append(": \"");
  			buffer.append(exception.getMessage());
  			buffer.append("\" \n");
  	
  			StackTraceElement array[] = exception.getStackTrace();
  	
  			for (StackTraceElement element : array) {
  				buffer.append("\tat ");
  				printStackTraceElement(element,buffer);
  				buffer.append('\n');
  			}
  	
  			if (exception.getCause() != null) {
  				buffer.append("Parent exception: ");
  				ret=formatException(exception.getCause(), buffer);
  			} else {
  				ret=buffer;
  			}
  		}
  		return ret;
  	}
docs: formatela la excepcion.
  
  @param exception excepcion
  @param buffer bufer
  @return StringBuilder