Class Error in Java
Error is thrown from an application to indicate that some abnormal conditions happened in the application. Error class forms the root of the error hierarchy in java. Subclasses of Error should generally not be caught. It causes the termination of the code.
The Error class is the superclass of all of the standard error classes that can be thrown in Java. The subclasses of Error are normally thrown by the class loader, the virtual machine, or other support code.
Application-specific code should not normally throw any of the standard error classes.
An Error or one of its subclasses is typically thrown when an unpredictable run-time error, such as running out of memory, occurs. Because of the unpredictable nature of the events that cause errors to be thrown, a method does not have to declare the Error class or any of its subclasses in the throws clause of its method declaration.
A Java program should not try to handle the standard error classes. Most of these error classes represent nonrecoverable errors and as such, they cause the Java run-time system to print an error message and terminate program execution.
Subclasses of Error need not be declared in the throws clause of a method definition.
getMessage() method returns a message associated with the error.
The structure of the class-Error is given as:
public class java.lang.Error extends java.lang.Throwable{
//constructor
public Error();
//constructs an empty Error object that is an object with no message specified.
public Error(String message);
//constructs an Error object with the message specified.
}
The class Error also inherits methods from class Object and Throwable.
From Object class | From Throwable class | |||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
clone() | fillInStackTrace() | |||||||||||||||||||||||||||||||||||||||||||||||
getClass() | getMessage() | |||||||||||||||||||||||||||||||||||||||||||||||
notify() | printStackTrace() | |||||||||||||||||||||||||||||||||||||||||||||||
wait() | printStackTrace(PrintWriter) | |||||||||||||||||||||||||||||||||||||||||||||||
wait(long, int) | getLocalizedMessage() | |||||||||||||||||||||||||||||||||||||||||||||||
wait(long) | printStackTrace(PrintStream) | |||||||||||||||||||||||||||||||||||||||||||||||
equals(Object) | ||||||||||||||||||||||||||||||||||||||||||||||||
toString() | ||||||||||||||||||||||||||||||||||||||||||||||||
finalize() | ||||||||||||||||||||||||||||||||||||||||||||||||
hashCode() | ||||||||||||||||||||||||||||||||||||||||||||||||
notifyAll() java.lang.Errors class provides several errors that can be thrown from java.lang package under several circumstances. The popular error classes are as follows:
|