In this section, you will learn how to get the stack trace of an exception as a String. We are providing you an example, which is throwing an IllegalArgumentException using Throwable class.
throwable.printStackTrace(printWriter)- This method prints the throwable exception and its stack trace to the specified print writer.
writer.toString()- This method returns the return the stack trace of an exception as a String.
Here is the code of GetStackTrace.java
import java.io.*;
|
Output will be displayed as:

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.
Ask Questions? Discuss: Java get Stack Trace as String
Post your Comment