List of Built in Exceptions in Java

Built in Exception are in java.lang package.
Before we see list of builtin Checked and UnChecked Exceptions, please read difference between checked and unchecked Exceptions.

Below is list of Checked Exceptions
Checked Exceptions are derived from Exception class

Exception name Reason & sample code
1. ClassNotFoundException Class is not found.
Class.forName(“p1.Abcd”);
2. CloneNotSupportedException Tried cloning an object that does not implement Cloneable interface.
obj.clone();
3. IllegalAccessException Do not have Access to a class.
obj.newInstance();
4. InstantiationException Cannot create an object of an abstract class or interface.
obj.newInstance();
5. InterruptedException One thread has been interrupted by another thread.
Thread.sleep();
6. NoSuchFieldException Field used does not exist.
cls.getField(“string3”);
7. NoSuchMethodException Method requested does not exist.
c.getMethod(“display”, null);

Below is list of UnChecked Exceptions
Unchecked Exception are classes derived from java.lang.Exception

Exception name Reason & Sample code
1. ArithmeticException Arithmetic error, such as divide-by-zero.
int i=32/0;
2. ArrayIndexOutOfBoundsException Array index is out-of-bounds.
arr[20]=56;
3. ArrayStoreException Assignment to an array element of an incompatible type.
arr=brr;
4. ClassCastException Invalid casting.
A obj = (A)(new B());
5. IllegalArgumentException Illegal argument used to invoke a method.
6. IllegalMonitorStateException Illegal monitor operation, such as waiting on an unlocked thread.
7. IllegalStateException Environment or application is in incorrect state.
8. IllegalThreadStateException Requested operation not compatible with current thread state.
9. IndexOutOfBoundsException index is out of range.
10. NegativeArraySizeException Array created with a negative size.
int arr[]=new int[-5];
11. NullPointerException Attempted to refer null.
12. NumberFormatException A String of invalid format attempted to convert.
Integer.parseInt(“3sd”);
13. SecurityException Attempt to violate security.
14. StringIndexOutOfBounds Attempt to index outside the bounds of a string.
str.charAt();
15. UnsupportedOperationException An unsupported operation was encountered.

You may also like to read:
How to create Custom exception in Java

One thought on “List of Built in Exceptions in Java”

Leave a Reply