The perfect place for easy learning...

Java Programming

×

Topics List


Built-in Exceptions in Java





The Java programming language has several built-in exception class that support exception handling. Every exception class is suitable to explain certain error situations at run time.

All the built-in exception classes in Java were defined a package java.lang.

Few built-in exceptions in Java are shown in the following image.

built-in exceptions in java

List of checked exceptions in Java

The following table shows the list of several checked exceptions.

S. No. Exception Class with Description
1 ClassNotFoundException

It is thrown when the Java Virtual Machine (JVM) tries to load a particular class and the specified class cannot be found in the classpath.

2 CloneNotSupportedException

Used 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.

3 IllegalAccessException

It is thrown when one attempts to access a method or member that visibility qualifiers do not allow.

4 InstantiationException

It is thrown when an application tries to create an instance of a class using the newInstance method in class Class , but the specified class object cannot be instantiated because it is an interface or is an abstract class.

5 InterruptedException

It is thrown when a thread that is sleeping, waiting, or is occupied is interrupted.

6 NoSuchFieldException

It indicates that the class doesn't have a field of a specified name.

7 NoSuchMethodException

It is thrown when some JAR file has a different version at runtime that it had at compile time, a NoSuchMethodException occurs during reflection when we try to access a method that does not exist.

List of unchecked exceptions in Java

The following table shows the list of several unchecked exceptions.

S. No. Exception Class with Description
1 ArithmeticException

It handles the arithmetic exceptions like dividion by zero

2 ArrayIndexOutOfBoundsException

It handles the situations like an array has been accessed with an illegal index. The index is either negative or greater than or equal to the size of the array.

3 ArrayStoreException

It handles the situations like when an attempt has been made to store the wrong type of object into an array of objects

4 AssertionError

It is used to indicate that an assertion has failed

5 ClassCastException

It handles the situation when we try to improperly cast a class from one type to another.

6 IllegalArgumentException

This exception is thrown in order to indicate that a method has been passed an illegal or inappropriate argument.

7 IllegalMonitorStateException

This indicates that the calling thread has attempted to wait on an object's monitor, or has attempted to notify other threads that wait on an object's monitor, without owning the specified monitor.

8 IllegalStateException

It signals that a method has been invoked at an illegal or inappropriate time.

9 IllegalThreadStateException

It is thrown by the Java runtime environment, when the programmer is trying to modify the state of the thread when it is illegal.

10 IndexOutOfBoundsException

It is thrown when attempting to access an invalid index within a collection, such as an array , vector , string , and so forth.

11 NegativeArraySizeException

It is thrown if an applet tries to create an array with negative size.

12 NullPointerException

it is thrown when program attempts to use an object reference that has the null value.

13 NumberFormatException

It is thrown when we try to convert a string into a numeric value such as float or integer, but the format of the input string is not appropriate or illegal.

14 SecurityException

It is thrown by the Java Card Virtual Machine to indicate a security violation.

15 StringIndexOutOfBounds

It is thrown by the methods of the String class, in order to indicate that an index is either negative, or greater than the size of the string itself.

16 UnsupportedOperationException

It is thrown to indicate that the requested operation is not supported.