¿Cómo puedo obtener el e.printStackTrace()
y almacenarlo en una variable String
? Quiero usar la cadena generada por e.printStackTrace()
más adelante en mi programa.Cómo almacenar printStackTrace en una cadena
Todavía soy nuevo en Java, así que no estoy muy familiarizado con StringWriter
que creo que será la solución. O si tiene alguna otra idea, por favor hágamelo saber. Gracias
@Zach L Apache Commons-lang3 - Gracias por su respuesta. funcionó para mí imprimir el seguimiento de la pila junto con un mensaje de error personalizado (personalizado). De nuevo, gracias por tu ayuda. –
Esto imprime las causas anidadas de la excepción lanzada también, que es justo lo que necesitaba. ¡Gracias! –
¿qué hay de cerrar 'PrintWriter' después del uso para liberar recursos? Al leer los documentos, descubrí que no es necesario para StringWriter. – jelies