Class Error in Java: Complete Guide in Just 5 Minutes

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{
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 classFrom Throwable class
wait(long, int)getLocalizedMessage()
See also  Class InstantiationError in Java

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:


Error classDescription
ThreadDeathIt is thrown in a victim thread where the stop() method with zero arguments is called.
UnsatisfiedLinkErrorThis error is thrown when JVM does not find the native-language definition of a particular method.
AbstractMethodErrorThis error is thrown when an abstract method is called from an application.
AssertionErrorThis error is thrown from ana application when an assertion fails.
ClassCircularityErrorThis error is thrown when JVM detects a circularity when it initializes the class.
ClassFormatErrorThis error is thrown when JVM tries to read a class file that is malformed or tampered or JVM can not identify this file as a valid class file.
ErrorChild class of throwable. It indicates that a serious issue has occurred during runtime. These issues are not created to catch operation to handle.
ExceptionInInitializerErrorThis error is thrown when JVM detects a serious issue in the static initialization process.
IllegalAccessErrorThis error is thrown when an application tries to access, edit or modify a file or tries to call a method and the application does not have access to those.
IncompatibleClassChangeErrorThis error is thrown when the class definition is changed incompatibly and the JVM tries to access the same.
InstantiationErrorThis error is thrown when the application calls a new operator to instantiate an interface or an abstract class.
InternalErrorThis error is thrown when JVM detects some internal error that is unexpected but unrecoverable.
LinkageErrorThis error occurs when the linking subclass has some dependency on another class.
NoClassDefFoundErrorThis error occurs when JVM(classloader) tries to load a class and the definition of the class is not found.
NoSuchFieldErrorThis error occurs when the application tries to access, edit, modify a field of a given object but the object has not the field present.
NoSuchMethodErrorThis error occurs when the application tries to access, edit, modify a method of a given object but the object has not the method present.
OutOfMemoryErrorThis error occurs when the garbage collectors can not provide enough space as a result the JVN can not provide memory to an object.
StackOverflowErrorThis error occurs when the application recurses too deeply and the stack is full.
UnknownErrorA serious error whose origination is unknown but thrown by JVM.
UnsupportedClassVersionErrorThis error occurs when the JVM detects the major and minor version is mismatching while reading a class file.
VerifyErrorThis error occurs when JVM (verifier) detects a well-formed class with some potential security violation or internal inconsistency.
VirtualMachineErrorThis error occurs when JVM runs out of resources or kind of broken and can not continue its operations.
AWTError Thrown from an application when a serious AWT error occurred during runtime.
See also  Literals in Java Simplified

Share and Enjoy !

Leave a Reply

Your email address will not be published. Required fields are marked *