Write a C# program to build a custom exception which raises an exception when the argument passed is a
negative number.
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Ashutosh ChaturvediPosted Apr 25, 2013, 9:06 AM
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.