Home » Core Java » UnChekcedException or RunTimeException in Java

UnChekcedException or RunTimeException in Java

What is RunTimeException :: 

1. RunTimeException are thrown by JVM during run time of a program.These exceptions are not raised during compile time of the program.It means compiler does not check these exceptions ,so these exceptions are called Unchecked exceptions.RunTimeExceptions are defined inside java.lang package.

2.  Hierarchy of RunTimeEXception  ::

Object –> Throwable –> Exception –> RuntimeException

3.  Examples of RunTimeException :: java.lang.ArrayIndexOutOfBoundsException ,java.lang.ArithmeticException,java.lang.NullPointerException etc.

Let us see a simple program which can throw RunTimeException.

Code Example to throw RunTimeException ::

The above program is going to throw RunTimeException in all the three scenarios.The program will terminate as soon as JVM throws first RunTimeException

How to Handle RunTimeException :: RunTimeException can be handled by keeping the code in try catch block with Super Exception handled.As java.lang.Exception class is super class of java.lang.RunTimeException ,the exception will be caught and if the exception is ignored then program will also not terminate.But it is not advisable to handle RunTimeException ,as it is a bug created by Java Developer and the developer is responsible to correct the code so that program will not throw RunTimeException.

Code Example to handle RunTimeException ::


Leave a comment

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

four × 5 =