Java: Most efficient way to convert an throwable/exception's entire stack trace into a ByteBuffer?

StackOverflow https://stackoverflow.com/questions/12499033

Frage

What is the most efficient method to convert an throwable/exception's entire stack trace into a ByteBuffer (in Java)?

Specifically, I need to log the entire exception into the database. The Thread.currentThread().getStackTrace() returns a list of StackTraceElement[] array.

Then, there is a printStackTrace() method in Throwable class?

War es hilfreich?

Lösung

If you really want to do that, this should be what you need:

ByteArrayOutputStream os = new ByteArrayOutputStream();
ex.printStackTrace(new PrintStream(os));
ByteBuffer bb = ByteBuffer.wrap(os.toByteArray());

Andere Tipps

You can use ExceptionUtils class in apache commons.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top