Logical Implementation


  • In this method we handle the exceptions by using logical statements
  • In real time programming first and fore most importance should be given for logical implementation only
  • If it’s not possible to handle any exception using logical implementation then we use, try catch implementation
Example 


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//Program to handle an Exception using Logical Implementation
namespace CAExceptions
{
    class ClsException1
    {
        static void Main(string[] args)
        {
            int a, b, c;
            Console.WriteLine("Enter Any Two Numbers:-");
            a = Convert.ToInt32(Console.ReadLine());
            b = Convert.ToInt32(Console.ReadLine());
            if (b == 0)
            {
                Console.WriteLine("Second Number Can not be Zero");
            }
            else
            {
                c = a / b;
                Console.WriteLine("Quotient Value is:-   "+c);
            }
            Console.ReadLine();
        }
    }
}




Output :-


No comments:

Post a Comment