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.
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.
Dinesh Thakur holds an B.C.A, MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular Computer Notes blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.
Related Articles
Basic Courses
Advance Courses