We have already read about ‘Exceptions’ in an earlier post. To recap:

Exceptions are certain error conditions which arise in a program. These error conditions are called ‘Exceptions’ and they are suitably handled. Programming bugs that are handled by making use of a ‘try-catch’ block or by stating that the method will throw an exception are known as checked exceptions.

Runtime Exception:

The Runtime Exception is not a checked exception. Runtime Exception is handled by solving the problem that is creating the Runtime Exception in the first place.

The class java.lang.RuntimeException extends from the java.lang.Exception class.

Some example of Runtime Exceptions are :

  • Arithmetic Exception(any number divided by 0)
  • NullPointer Exception(trying to perform an operation on a ‘null object’)
  • ArrayIndexOutOfBounds Exception(is trying to access an array away beyond the limit of the array – for example, a Runtime Exception will be thrown when we try to access the 6th element of a 5 element array)

Let us see an example of a Runtime Exception:

 

In this example, we are trying to access the 6th element of a 5 element array. This throws a Runtime Exception. In this case, we solve the Runtime Exception by declaring the array to be the appropriate size.

We have seen the Runtime Exception in this post.

Come back tomorrow as we discuss the ‘String’ class! 🙂

I am participating in #BlogchatterA2Z by Blogchatter 

(Visited 73 times, 1 visits today)

Related Posts

Leave a Reply