java.lang
Class Throwable

java.lang.Object
  |
  +--java.lang.Throwable
Direct Known Subclasses:
Error, Exception

public class Throwable
extends Object

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 class 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:

     try {
         int a[] = new int[2];
         a[4];
     } catch (IndexOutOfBoundsException e) {
         System.out.println("exception: " + e.getMessage());
         e.printStackTrace();
     }
 

Since:
JDK1.0

Constructor Summary
Throwable()
          Constructs a new Throwable with no detail message.
Throwable(String message)
          Constructs a new Throwable with the specified detail message.
 
Method Summary
 String getMessage()
          Returns the detail message of this throwable object.
 void printStackTrace()
          Prints this Throwable and its backtrace to the standard error stream.
 String toString()
          Returns a short description of this throwable object.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Throwable

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

Since:
JDK1.0

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.
Since:
JDK1.0
Method Detail

getMessage

public String getMessage()
Returns the detail message of this throwable object.

Returns:
the detail message of this Throwable, or null if this Throwable does not have a detail message.
Since:
JDK1.0

toString

public String toString()
Returns a short description of this throwable object.

Overrides:
toString in class Object
Returns:
a string representation of this Throwable.
Since:
JDK1.0

printStackTrace

public void printStackTrace()
Prints this Throwable and its backtrace to the standard error stream.

Since:
JDK1.0
See Also:
System.err