Following are some important methods of Exception class:
- public Throwable getCause() – Returns the cause of this throwable or
null
if the cause is nonexistent or unknown. (The cause is the throwable that caused this throwable to get thrown.) - public String getLocalizedMessage() – Creates a localized description of this throwable. Subclasses may override this method in order to produce a locale-specific message. For subclasses that do not override this method, the default implementation returns the same result as
getMessage()
. - public String getMessage() – Returns the detail message string of this throwable.
- public void printStackTrace() – Prints this throwable and its backtrace to the standard error stream. This method prints a stack trace for this
Throwable
object on the error output stream that is the value of the fieldSystem.err
. The first line of output contains the result of thetoString()
method for this object. Remaining lines represent data previously recorded by the methodfillInStackTrace()
. - public String toString() – Returns a short description of this throwable. The result is the concatenation of:
- the name of the class of this object
- “: ” (a colon and a space)
- the result of invoking this object’s
getLocalizedMessage()
method
If getLocalizedMessage returns null
, then just the class name is returned.