Top 10 Exception in Java

checked and unchecked exceptions is that checked exceptions are forced by compiler and used to indicate exceptional conditions that are out of the control of the program (for example, I/O errors), while unchecked exceptions are occurred during runtime and used to indicate ...

All Exception divided into two type
1-JVM Exception
2-Programatic Exception

1-ArrayIndexOutOfBoundsException

* it is child class of RuntimeException it is unchecked Exception.
* it is automatically raised by JVM .

2- NullPointerException

  • it is child class of RuntimeException it is unchecked Exception.
  • it is automatically raised by JVM .
  • when ever we are trying to perform any opration on Null

3-StackOverFlowError

  • it is a child class of error and it is unchecked .
  • When you recursly method invocation then you will get StackOverFlowError .

4- NoClassDefFoundError

  • when Java Virtual Machine is not able to find a particular class at runtime
  • it is a child class of error and it is unchecked .
  • it is automatically raised by JVM .

5-ClassCastException

  • It is child class of RuntimeException it is unchecked Exception.
  • It is automatically raised by JVM .
  • When ever we are trying to typecast parent to child type.

6- ExceptionInInitializerError

  • if any exception occurs while performing initilazation for static variable and while executing static blocks
  • It is automatically raised by JVM .

public class ArraysDS {
static {
String x = null;
System.out.println(x.length());}
public static void main(String[] args) {}}

7-IllegalArgumentException

  • This exception indicates that a method is called with incorrect input arguments.
  • Raised explicitly by programmer or by API developer

8- NumberFormatException

  • when you try to convert String to Number type but String is properly formatted.
  • Raised explicitly by programmer or by API developer

9 -IllegalStateException

  • Raised explicitly by programmer or by API developer
  • Once session expire we can’t call any method on that object otherwise we will get IllegalStateException.

10 -AssertionError

  • it is a child class of error ,hence it is unchecked.
  • Raised explicitly by programmer or by API developer.
  • when you assert statement is fail then you will get AssertionError.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Sanjay Singh

Sanjay Singh

Java||Spring-Boot|| Micro services Application developer|| INDIA