java tutorial - Java - Built-in exceptions - java programming - learn java - java basics - java for beginners
- Java defines several exception classes within the standard java.lang package.
- The most common of these exceptions are subclasses of the standard type RuntimeException. Since java.lang is implicitly imported into all java programs, most exceptions received from RuntimeException are automatic.
- Java defines several other types of exceptions that are related to its different class libraries. The following is a list of Unchecked RuntimeException.
No. | Exception and Description |
1 | java.lang.ArithmeticException Arithmetic error, for example, division by zero. |
2 | java.lang.ArrayIndexOutOfBoundsException The array index is out of bounds. |
3 | java.lang.ArrayStoreException Assign an incompatible type to an array element. |
4 | java.lang.ClassCastException Invalid cast of types. |
5 | java.lang.IllegalArgumentException Invalid argument used to call the method. |
6 | java.lang.IllegalMonitorStateException Invalid operation of the monitor, for example, waiting for an unlocked stream. |
7 | java.lang.IllegalStateException The environment or application is in the wrong state. |
8 | java.lang.IllegalThreadStateException The requested operation is incompatible with the current state of the stream. |
9 | java.lang.IndexOutOfBoundsException Some type of index is out of bounds. |
10 | java.lang.NegativeArraySizeException The array was created with a negative size. |
11 | java.lang.NullPointerException Invalid use of the null reference. |
12 | java.lang.NumberFormatException Invalid conversion of a string to a number format. |
13 | java.lang.SecurityException Attempt to break security. |
14 | java.lang.StringIndexOutOfBounds An attempt to index outside the string. |
15 | java.lang.UnsupportedOperationException An unsupported operation was detected. |
The following is a list of the Checked Exceptions in Java defined in java.lang
No. | Exception and Description |
1 | java.lang.ClassNotFoundException Class not found. |
2 | java.lang.CloneNotSupportedException Attempted to clone an object that does not implement the Cloneable interface. |
3 | java.lang.IllegalAccessException Access to the class is denied. |
4 | java.lang.InstantiationException An attempt was made to create an object of an abstract class or interface. |
5 | java.lang.InterruptedException One thread was interrupted by another thread. |
6 | java.lang.NoSuchFieldException The requested field does not exist. |
7 | java.lang.NoSuchMethodException The requested method does not exist. |