Java Reference
In-Depth Information
The
class
Throwable
contains various constructors and methods, some of which are
described in Table 11-1.
TABLE 11-1
Constructors and Methods of the
class
Throwable
public
Throwable()
//Default constructor
//Creates an instance of Throwable with an empty message string
public
Throwable(String strMessage)
//Constructor with parameters
//Creates an instance of Throwable with message string
//specified by the parameter strMessage
public
String getMessage()
//Returns the detailed message stored in the object
public void
printStackTrace()
//Method to print the stack trace showing the sequence of
//method calls when an exception occurs
public void
printStackTrace(PrintWriter stream)
//Method to print the stack trace showing the sequence of
//method calls when an exception occurs. Output is sent
//to the stream specified by the parameter stream.
public
String toString()
//Returns a string representation of the Throwable object
The methods
getMessage
,
printStackTrace
, and
toString
are
public
and are
inherited by the subclasses of the
class
Throwable
.
The
class
Exception
and its subclasses, some of which are shown in Figures 11-2 to
11-4, are designed to catch exceptions that should be caught and processed during
program execution, thus making a program more robust. The sections that follow discuss
how to use the
class
Exception
and its subclasses to handle various types of exceptions,
and how to create your own exception classes.
Search WWH ::
Custom Search