Sobes.tech
Junior — Middle

Can you list the main exception classes that inherit from RuntimeException in Java?

sobes.tech AI

Answer from AI

In Java, RuntimeException is the base class for unchecked exceptions that do not require mandatory catching or declaration.

Main classes inheriting from RuntimeException include:

  • NullPointerException — attempting to access an object via a null reference.
  • ArrayIndexOutOfBoundsException — accessing an array out of its bounds.
  • IllegalArgumentException — passing an invalid argument to a method.
  • IllegalStateException — calling a method in an inappropriate object state.
  • ClassCastException — incorrect type casting.
  • ArithmeticException — arithmetic error, such as division by zero.
  • NumberFormatException — error converting a string to a number.

These exceptions usually indicate logical errors in the code that should be fixed, rather than handled.

Can you list the main exception classes that inherit… - sobes.tech