Class | Tree | Index | Help
PREV CLASS | NEXT CLASS FRAMES  | NO FRAMES
SUMMARY:  INNER | FIELD | CONSTR | METHOD DETAIL:  FIELD | CONSTR | METHOD

Class java.lang.Throwable

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

public class Throwable
extends Object
implements java.io.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();
     }
 

Since:
JDK1.0
Version:
1.31, 01/26/97
See Also:
Serialized Form

Field Summary
Object backtrace
          Native code saves some indication of the stack backtrace in this slot.
String detailMessage
          Specific details about the Throwable.
static long serialVersionUID
          use serialVersionUID from JDK 1.0.2 for interoperability
 
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 execution stack trace.
String getLocalizedMessage()
          Creates a localized description of this Throwable.
String getMessage()
          Returns the detail message of this throwable object.
void printStackTrace0(Object s)
           
void printStackTrace()
          Prints this Throwable and its backtrace to the standard error stream.
void printStackTrace(java.io.PrintStream s)
          Prints this Throwable and its backtrace to the specified print stream.
void printStackTrace(java.io.PrintWriter s)
          Prints this Throwable and its backtrace to the specified print writer.
String toString()
          Returns a short description of this throwable object.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notifyAll, notify, registerNatives, toString, wait, wait, wait
 

Field Detail

backtrace

private transient Object backtrace
Native code saves some indication of the stack backtrace in this slot.

detailMessage

private String detailMessage
Specific details about the Throwable. For example, for FileNotFoundThrowables, this contains the name of the file that could not be found.

serialVersionUID

private static final long serialVersionUID
use serialVersionUID from JDK 1.0.2 for interoperability
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 detail message.
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.

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().

toString

public String toString()
Returns a short description of this throwable object.
Returns:
a string representation of this Throwable.
Overrides:
toString in class Object

printStackTrace

public void printStackTrace()
Prints this Throwable and its backtrace to the standard error stream.
See Also:
java.lang.System#err

printStackTrace

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

printStackTrace

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

printStackTrace0

private void printStackTrace0(Object s)

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:

     try {
         a = b / c;
     } catch(ArithmeticThrowable e) {
         a = Number.MAX_VALUE;
         throw e.fillInStackTrace();
     }
 
Returns:
this Throwable object.
See Also:
printStackTrace()


Class | Tree | Index | Help
PREV CLASS | NEXT CLASS FRAMES  | NO FRAMES
SUMMARY:  INNER | FIELD | CONSTR | METHOD DETAIL:  FIELD | CONSTR | METHOD