Class java.lang.Throwable
All Packages Class Hierarchy This Package Previous Next Index
Class java.lang.Throwable
java.lang.Object
|
+----java.lang.Throwable
- 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();
}
-
Throwable()
- Constructs a new Throwable with no detail message.
-
Throwable(String)
- Constructs a new Throwable with the specified detail message.
-
fillInStackTrace()
- Fills in the excecution stack trace.
-
getMessage()
- Gets the detail message of the Throwable.
-
printStackTrace()
- Prints the Throwable and the Throwable's stack trace.
-
printStackTrace(PrintStream)
-
-
toString()
- Returns a short description of the Throwable.
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
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
All Packages Class Hierarchy This Package Previous Next Index