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
Output will be displayed as:
Rs. 20,000 US$ 300
Today: Rs. 10,000 US$150
Course Duration: 30 hrs
Posted on: November 1, 2008 If you enjoyed this post then why not add us on Google+? Add us to your Circles