Throwable toString() method in Java with Examples
The toString() method of Java.lang.Throwable class used to return a String representation of this Throwable which consists of the name of the class of this object, a colon and a space(“: “) and a string which is same as result of invoking this object’s getLocalizedMessage() method and If getLocalizedMessage returns null, then just the class name is returned.
public String toString()
Return Value: This method returns String representation of this Throwable if a Exception occurs.
Below programs illustrate the toString() method of Throwable class:
Exception: java.lang.Exception: New Exception Thrown
Exception: java.lang.ArithmeticException: / by zero