Packages  This Package  Prev  Next  Index  

§1.21 Class Throwable

public  class  java.lang.Throwable
    extends  java.lang.Object  (I-§1.12)
{
        // Constructors
    public Throwable();	§1.21.1
    public Throwable(String  message);	§1.21.2

        // Methods
    public Throwable fillInStackTrace();	§1.21.3
    public String getMessage();	§1.21.4
    public void printStackTrace();	§1.21.5
    public void printStackTrace(PrintStream  s);	§1.21.6
    public String toString();	§1.21.7
}
The Throwable class is the superclass of all errors and exceptions in the Java language. Only objects that are instances of this class (or of one of its subclasses) are thrown by the Java Virtual Machine or can be thrown by the Java throw statement. Similarly, only this class or one of its subclasses can be the argument type in a catch clause.

A Throwable contains a snapshot of the execution stack of its thread at the time it was created. It can also contain a message string that gives more information about the error.

Here is one example of catching an exception:


Constructors

Throwable

public Throwable()
Constructs a new Throwable with no detail message. The stack trace is automatically filled in.

Throwable

public Throwable(String message)
Constructs a new Throwable with the specified detail message. The stack trace is automatically filled in.
Parameters:
message - the detail message

Methods

fillInStackTrace

public Throwable fillInStackTrace()
Fills in the execution stack trace. This method is useful when an application is re-throwing an error or exception. For example:

getMessage

public String getMessage()
Returns:
the detail message of this Throwable, or null if this Throwable does not have a detailed message.

printStackTrace

public void printStackTrace()
Prints this Throwable and its backtrace to the standard error (I-§1.18.1) output stream.

printStackTrace

public void printStackTrace(PrintStream s)
Prints this Throwable and its backtrace to the specified print stream.

toString

public String toString()
Returns:
a string representation of this Throwable.
Overrides:
toString in class Object (I-§1.12.9).

Packages  This Package  Prev  Next  Index
Java API Document (HTML generated by dkramer on April 22, 1996)
Copyright © 1996 Sun Microsystems, Inc. All rights reserved
Please send any comments or corrections to doug.kramer@sun.com