Team LiB
Previous Section Next Section

Throwablejava.lang

Java 1.0serializable

This is the root class of the Java exception and error hierarchy. All exceptions and errors are subclasses of Throwable. The getMessage( ) method retrieves any error message associated with the exception or error. The default implemenation of getLocalizedMessage( ) simply calls getMessage( ), but subclasses may override this method to return an error message that has been localized for the default locale.

It is often the case that an Exception or Error is generated as a direct result of some other exception or error, perhaps one thrown by a lower-level API. As of Java 1.4 and later, all Throwable objects may have a "cause" which specifies the Throwable that caused this one. If there is a cause, pass it to the THRowable( ) constructor, or to the initCause( ) method. When you catch a Throwable object, you can obtain the Throwable that caused it, if any, with getCause( ).

Every THRowable object has information about the execution stack associated with it. This information is initialized when the THRowable object is created. If the object will be thrown somewhere other than where it was created, or if it caught and will be re-thrown, you can use fillInStackTrace( ) to capture the current execution stack before throwing it. printStackTrace( ) prints a textual representation of the stack to the specified PrintWriter, PrintStream, or to the System.err stream. In Java 1.4, you can also obtain this information with getStackTrace( ) which returns an array of StackTraceElement objects describing the execution stack.

Figure 10-66. java.lang.Throwable


public class Throwable implements Serializable {
// Public Constructors
     public Throwable( );  
     public Throwable(String message);  
1.4  public Throwable(Throwable cause);  
1.4  public Throwable(String message, Throwable cause);  
// Public Instance Methods
     public Throwable fillInStackTrace( );                                native synchronized
1.4  public Throwable getCause( );                                    default:null
1.1  public String getLocalizedMessage( );                            default:null
     public String getMessage( );                                         default:null
1.4  public StackTraceElement[ ] getStackTrace( );  
1.4  public Throwable initCause(Throwable cause);                   synchronized
     public void printStackTrace( );  
     public void printStackTrace(java.io.PrintStream s);  
1.1  public void printStackTrace(java.io.PrintWriter s);  
1.4  public void setStackTrace(StackTraceElement[ ] stackTrace);  
// Public Methods Overriding Object
     public String toString( );  
}

Subclasses

Error, Exception

Passed To

Too many methods to list.

Returned By

java.io.WriteAbortedException.getCause( ), ClassNotFoundException.{getCause( ), getException( )}, ExceptionInInitializerError.{getCause( ), getException( )}, java.lang.reflect.InvocationTargetException.{getCause( ), getTargetException( )}, java.lang.reflect.UndeclaredThrowableException.{getCause( ), getUndeclaredThrowable( )}, java.security.PrivilegedActionException.getCause( ), java.util.logging.LogRecord.getThrown( ), javax.xml.transform.TransformerException.{getCause( ), getException( ), initCause( )}, javax.xml.xpath.XPathException.getCause( )

Thrown By

Object.finalize( ), java.lang.reflect.InvocationHandler.invoke( )

    Team LiB
    Previous Section Next Section