Skip to content

Kindly help.

Shraddha Bhat

Asked Apr 25, 2013, 12:39 AM EDT1 answer
Share
LinkedInX
Write a C# program to build a custom exception which raises an exception when the argument passed is a
negative number.

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • Ashutosh Chaturvedi
    0
    C#
    using System;
    using System.Collections.Generic;
    using System.Text;
    namespace ConsoleApplication5
    {
        class Program
        {
            static void Main(string[] args)
            {
                int x, y, z = 0;
                try
                {
                    Console.WriteLine("Enter The Value of X");
                    x = Convert.ToInt32(Console.ReadLine());
                    Console.WriteLine("Enter The Value of Y");
                    y = Convert.ToInt32(Console.ReadLine());
                    z = x / y;
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                }
                finally
                {
                    Console.WriteLine("The Division is : " + z);
                }
            }
        }
    }


    Note:- you can manipulate this code as per requirement.

    0