Constructors
There are four constructors in the Throwable class:
• Throwable ()
• Throwable (String message)
• Throwable (String message, Throwable cause) • Throwable (Throwable cause)
The first two allow constructing an exception object with or without a String message encapsulated in the object.
Methods
There are several methods in the Throwable class. Three useful methods of the Throwable class that provide information about an exception are the following:
• getMessage (): Returns the message that was encapsulated when the object was initiated. It returns null, if there is no message.
• toString(): returns a brief description about the exception of throwable object.
• printStacktrace (): prints the stack trace.
StackTrace is a list of the methods executed in sequence that lead to the exception and it is typically used to show the (unhandled) run-time errors on the screen.
The methods of the Throwable class that deal with StackTrace are the following:
• fililnStackTrace ()
• getStackTrace ()
• printStackTrace ()
• setStackTrace (Stack TraceElement [] stack Trace)
When an exceptional condition occurs within a method, the method may instantiate an exception object and hand it to the run-time system to deal with it. This is called throwing an exception.