站内搜索: 请输入搜索关键词
当前页面: 在线文档首页 > JDK 5 Documentation v1.1.8, Java 2 SDK 英文文档

Class java.lang.Throwable - JDK 5 Documentation v1.1.8, Java 2 SDK 英文文档

All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class java.lang.Throwable

java.lang.Object
   |
   +----java.lang.Throwable

public class Throwable
extends Object
implements Serializable
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 (ArrayIndexOutOfBoundsException e) {
         System.out.println("exception: " + e.getMessage());
         e.printStackTrace();
     }
 


Constructor Index

 o Throwable()
Constructs a new Throwable with no detail message.
 o Throwable(String)
Constructs a new Throwable with the specified detail message.

Method Index

 o fillInStackTrace()
Fills in the execution stack trace.
 o getLocalizedMessage()
Creates a localized description of this Throwable.
 o getMessage()
Returns the detail message of this throwable object.
 o printStackTrace()
Prints this Throwable and its backtrace to the standard error stream.
 o printStackTrace(PrintStream)
Prints this Throwable and its backtrace to the specified print stream.
 o printStackTrace(PrintWriter)
Prints this Throwable and its backtrace to the specified print writer.
 o toString()
Returns a short description of this throwable object.

Constructors

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

 o 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

 o 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.
 o getLocalizedMessage
 public String getLocalizedMessage()
Creates a localized description of this Throwable. Subclasses may override this method in order to produce a locale-specific message. For subclasses that do not override this method, the default implementation returns the same result as getMessage().

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

Returns:
a string representation of this Throwable.
Overrides:
toString in class Object
 o printStackTrace
 public void printStackTrace()
Prints this Throwable and its backtrace to the standard error stream.

See Also:
err
 o printStackTrace
 public void printStackTrace(PrintStream s)
Prints this Throwable and its backtrace to the specified print stream.

 o printStackTrace
 public void printStackTrace(PrintWriter s)
Prints this Throwable and its backtrace to the specified print writer.

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

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

Returns:
this Throwable object.
See Also:
printStackTrace

All Packages  Class Hierarchy  This Package  Previous  Next  Index

Submit a bug or feature - Version 1.1.8 of Java Platform API Specification
Java is a trademark or registered trademark of Sun Microsystems, Inc. in the US and other countries.
Copyright 1995-1999 Sun Microsystems, Inc. 901 San Antonio Road,
Palo Alto, California, 94303, U.S.A. All Rights Reserved.