Escribir una traza con printStackTrace();

Domingo, 15 de Octubre de 2006

A veces podemos querer tener la traza de una Exception para pintarla en nuestro JSP de error con un formato bonito o enviarla por correo. El método siguiente nos devuelve un String con el resultado del printStackTrace() de un objeto Throwable (el padre de Exception y Error):

public String getStackTrace(Throwable e) {
        StringWriter stringWriter = new StringWriter();
        e.printStackTrace(new PrintWriter(stringWriter));
        return stringWriter.toString();
}

Hacer un comentario

XHTML: Puedes utilizar las siguientes etiquetas:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>

Verification Image

Debes leer y teclear los caracteres entre 0..9 y A..F para enviar la respuesta.