Skip to content
Advertisement

How do I write the exception from printStackTrace() into a text file in Java?

I need to capture the exception in a text file in Java. For example:

JavaScript

Using getMessage() works, but it only shows the error message. I want all the information in the printStackTrace() including line numbers.

Advertisement

Answer

It accepts a PrintStream as a parameter; see the documentation.

JavaScript

See also Difference between printStackTrace() and toString()

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement