Class java.lang.Exception
All Packages This Package Previous Next
Class java.lang.Exception
java.lang.Object
|
+----java.lang.Exception
-
public class
Exception
-
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.
An example of catching an exception:
try {
int a[] = new int[2];
a[4];
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println("an exception occurred: " + e.getMessage());
e.printStackTrace();
}
-
Version:
-
1.12, 31 Jan 1995
-
Exception()
-
Constructs an exception with no detail message.
-
Exception(String)
-
Constructs an exception with the specified detail message.
-
fillInStackTrace()
-
Fills in the excecution stack trace.
-
getMessage()
-
Gets the message.
-
printStackTrace()
-
Prints the exception and the exception's stack trace.
-
toString()
-
Returns a short description of the exception.
Exception
public Exception()
-
Constructs an exception with no detail message. The stack
trace is automatically filled in.
Exception
public Exception(String message)
-
Constructs an exception with the specified detail message.
The stack trace is automatically filled in.
-
Parameters:
-
message
-
the detail message
getMessage
public String getMessage()
-
Gets the message.
-
Returns:
-
the detail message of the exception
toString
public String toString()
-
Returns a short description of the exception.
-
Returns:
-
a string describing the exception
-
Overrides:
-
toString in class Object
printStackTrace
public void printStackTrace()
-
Prints the exception and the exception's stack trace.
fillInStackTrace
public Exception fillInStackTrace()
-
Fills in the excecution stack trace. This is useful only
when rethrowing an exception. For example:
try {
a = b / c;
} catch(ArithmeticException e) {
a = Number.MAX_VALUE;
throw e.fillInStackTrace();
}
-
Returns:
-
the exception itself
-
See Also:
-
printStackTrace
All Packages This Package Previous Next