java.lang
Class Throwable

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

public class Throwable
extends Object

An object signalling that an exceptional condition has occurred. All exceptions are a subclass of Exception. An exception contains a snapshot of the execution stack, this snapshot is used to print a stack backtrace. An exception also contains a message string. Here is an example of how to catch an exception:

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


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
 Throwable fillInStackTrace()
          Fills in the excecution stack trace.
 String getMessage()
          Gets the detail message of the Throwable.
 void printStackTrace()
          Prints the Throwable and the Throwable's stack trace.
 void printStackTrace(PrintStream s)
           
 String toString()
          Returns a short description of the Throwable.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, 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.


Throwable

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

Parameters:
message - the detailed message
Method Detail

getMessage

public String getMessage()
Gets the detail message of the Throwable. A detail message is a String that describes the Throwable that has taken place.

Returns:
the detail message of the throwable.

toString

public String toString()
Returns a short description of the Throwable.

Overrides:
toString in class Object

printStackTrace

public void printStackTrace()
Prints the Throwable and the Throwable's stack trace.


printStackTrace

public void printStackTrace(PrintStream s)

fillInStackTrace

public Throwable fillInStackTrace()
Fills in the excecution stack trace. This is useful only when rethrowing a Throwable. For example:

	   try {
	        a = b / c;
	   } catch(ArithmeticThrowable e) {
		a = Number.MAX_VALUE;
	        throw e.fillInStackTrace();
	   }
 

Returns:
the Throwable itself.
See Also:
printStackTrace()