![]() |
VOOZH | about |
RuntimeException is the superclass of all classes that exceptions are thrown during the normal operation of the Java VM (Virtual Machine). The RuntimeException and its subclasses are unchecked exceptions. The most common exceptions are NullPointerException, ArrayIndexOutOfBoundsException, ClassCastException, InvalidArgumentException etc.
Example 1:
example of runtime exception
Now let's create one more common example of run time exception called ArrayIndexOutOfBoundsException. This exception occurs when we want to access array more than its size for example we have an array of size 5, array[5] and we want to access array[6]. This is an ArrayIndexOutOfBoundsException because 6 indexes does not exist in this array.
Example 2:
Output
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 5 out of bounds for length 5 at GFG.main(File.java:10)