List of Unchecked Exception in Java

Unchecked exceptions in Java, also known as runtime exceptions, are exceptions that are not required to be caught or declared in a method’s throws clause. These exceptions are typically caused by programming errors or unexpected conditions and often represent scenarios that are recoverable with proper coding practices.

List of Unchecked Exception in Java

 List of Unchecked Exception in Java

Here is a list of some common unchecked exception in Java:

ArithmeticException

Thrown when an exceptional arithmetic condition has occurred. For example, an integer “divide by zero” throws an instance of this class.

Common Unchecked Exceptions in Java
Screen Shot 2020-04-17 at 9.06.24 PM

ArrayIndexOutOfBoundsException

Thrown to indicate that 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.

Screen Shot 2020-04-17 at 9.10.36 PM
Screen Shot 2020-04-17 at 9.10.43 PM

NullPointerException

Thrown when an application attempts to use null in a case where an object is required.

Screen Shot 2020-04-17 at 9.13.52 PM
Screen Shot 2020-04-17 at 9.13.59 PM

NumberFormatException

Thrown to indicate that the application has attempted to convert a string to one of the numeric types, but that the string does not have the appropriate format.

Screen Shot 2020-04-17 at 9.17.26 PM
Screen Shot 2020-04-17 at 9.17.33 PM

ConcurrentModificationException

This exception may be thrown by methods that have detected concurrent modification of an object when such modification is not permissible.
For example, it is not generally permissible for one thread to modify a Collection while another thread is iterating over it.

Screen Shot 2020-04-17 at 9.32.01 PM
Screen Shot 2020-04-17 at 9.32.16 PM

IllegalArgumentException

Thrown to indicate that a method has been passed an illegal or inappropriate argument.

Screen Shot 2020-04-17 at 9.39.20 PM
Screen Shot 2020-04-17 at 9.40.53 PM

IllegalStateException

Signals that a method has been invoked at an illegal or inappropriate time. In other words, the Java environment or Java application is not in an appropriate state for the requested operation.

Screen Shot 2020-04-17 at 9.46.39 PM
Screen Shot 2020-04-17 at 9.46.46 PM

ClassCastException

Thrown when an attempt is made to cast an object to an incompatible class.

public class ClassCastExceptionExample {
    public static void main(String[] args) {
        try {
            // Creating an Integer object
            Object obj = new Integer(10);

            // Attempting to cast Integer to String
            String str = (String) obj; // This line will throw ClassCastException
        } catch (ClassCastException e) {
            System.out.println("ClassCastException caught: " + e.getMessage());
        }
    }
}

Output

ClassCastException caught: java.lang.Integer cannot be cast to java.lang.String

Conclusion : List of Unchecked Exception in Java

In this article, we explored the list of Unchecked Exception in Java in great details. Hopefully, this will enable developers to write Java Code effectively keeping in mind these unchecked exceptions.

Read More : List of Checked Exception in Java

Leave a Reply

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