java.lang Errors and Exceptions Part - I

Some of the Errors and Exceptions of java.lang

AbstractMethodError: This is thrown when an application tries to call an abstract method.

ArithmeticException:  This is thrown when an exceptional arithmetic condition has occurred. For example, an integer "divide by zero" throws an instance of this class.


ArrayIndexOutOfBoundsException: This is thrown to indicate that an array has been accessed with an illegal index.


ArrayStoreException: This is thrown to indicate that an attempt has been made to store the wrong type of object into an array of objects.


AssertionError: This is thrown to indicate that an assertion has failed.

BootstrapMethodError: This is thrown to indicate that an invokedynamic instruction or a dynamic constant failed to resolve its bootstrap method and arguments.


ClassCastException: This is thrown to indicate that the code has attempted to cast an object to a subclass of which it is not an instance.


ClassCircularityError: This is thrown when the Java Virtual Machine detects a circularity in the superclass hierarchy of a class is loaded.


ClassFormatError: This is thrown when the Java Virtual Machine attempts to read a class file and determines that the file is malformed or otherwise cannot be interpreted as a class file.


ClassNotFoundException: Thrown when an application tries to load in a class through its string name using:
  • The forName method in class Class.
  • The findSystemClass method in class ClassLoader .
  • The loadClass method in class ClassLoader.

but no definition for the class with the specified name could be found


CloneNotSupportedException: Thrown to indicate that the clone method in class Object has been called to clone an object, but that the object's class does not implement the Cloneable interface.


EnumConstantNotPresentException: This is thrown when an application tries to access an enum constant by name and the enum type contains no constant with the specified name.


ExceptionInInitializerError: It is thrown to indicate that an exception occurred during the evaluation of a static initializer or the initializer for a static variable.


IllegalAccessError: This is thrown if an application attempts to access or modify a field, or to call a method that it does not have access to.


IllegalAccessException: It is thrown when an application tries to reflectively create an instance (other than an array), set or get a field, or invoke a method, but the currently executing method does not have access to the definition of the specified class, field, method or constructor.


IllegalArgumentException: This is thrown to indicate that a method has been passed an illegal or argument.


IllegalCallerException: This is thrown to indicate that a method has been called by an inappropriate caller.


IllegalMonitorStateException: This is thrown to indicate that a thread has attempted to wait on an object's monitor.


IllegalStateException: This signals that a method has been invoked at an illegal or inappropriate time.


IllegalThreadStateException: This is thrown to indicate that a thread is not in an appropriate state for the requested operation.


IncompatibleClassChangeError: This is thrown when an incompatible class change has occurred to some class definition.


IndexOutOfBoundsException: This is thrown to indicate that an index is out of range.


InstantiationError: This is thrown when an application tries to use the Java new construct to instantiate an abstract class or an interface.


ArrayIndexOutOfBoundsException code:

Approach:

Java:

public class IndexOut {
    public static void main(String[] args) {

        int arr[] = { 12345 };

        System.out.println(arr[5]);
    }
}

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 5 out of bounds for length 5


No comments:

Post a Comment