Exception Handling

Exception Handling

An exception is an event or abnormal condition that breaks the normal flow of the program or we can say that an exception is a problem that arises during the execution of the program.

Exception Handling:

There are two types of Exception Handling:
1. Checked Exception
2. Unchecked Exception
Checked Exception: The exception that are checked at compile time are known as Checked Exception or we can also define checked exception as, The classes that extend throwable class except Runtime Exception are known as checked exception eg. IOException, SQLException etc.

Unchecked Exception: The exception that are checked at runtime are known as Unchecked Exception or we can also define unchecked exception as, The class that extend Runtime Exception are known as unchecked exception eg. Arithmetic Exception, Null Pointer Exception and Array Indexout of Bound Exception etc.

Example of Exception Handling:

 public class ExceptionEx
{
        public static void main(String args[])
        {
              try
              {
                         int n;
                         n=100/0;
                         System.out.println("Value of n is "+n);
               }
               catch(ArithmeticException er)
               {
                          System.out.println(er);
               }
               System.out.println("Hello i am out of try catch block");
          }
 }
Output:
Exception in thread main java.lang.ArithmeticException:/ by zero
Hello i am out of try catch block

Post a Comment

0 Comments