Saturday 26 December 2015

What is Unchecked Exception in java with example

Unchecked Exception in Java is those Exceptions whose handling is not verified during Compile time.

Unchecked Exceptions mostly arise due to programming errors like accessing method of a null object, accessing element outside an array bonding or invoking method with illegal arguments. 




Some important's points
  1. Runtime Exception are also known as unchecked exception.
  2. UnCheckedException are mostly programming mistakes.
  3. Unchecked Exception are of RuntimeException.
  4. Unchecked Exception is direct sub Class of RuntimeException.



Examples of UncheckedExceptions

  1. ArithmeticException
  2. NullPointerException
  3. ArrayIndexOutOfBoundException
  4. NegativeArraySizeException.....etc

Through Example:


class DemoUncheckedExceptions {  

   public static void main(String args[])

   {

int num1=20;

int num2=0;

/*If I'm dividing with an integer with 0

* it should throw ArithmeticException*/

int result=num1/num2;

System.out.println(result);

   }

}








No comments:

Post a Comment