Your Ad Here

Friday, May 30, 2008

Exception Handling - Addition Of Two Byte Numbers

/* C sharp program on exception handling. Addition of two byte numbers. */

using System;
using System.Collections.Generic;
using System.Text;

namespace Program1
{
class check
{
public static void Main()
{
byte numOne;
byte numTwo;
byte result;

Console.WriteLine("Byte Size - (0-255)");
Console.Write("Enter a byte number : ");
numOne = Convert.ToByte(Console.ReadLine());
Console.Write("Enter a byte number : ");
numTwo = Convert.ToByte(Console.ReadLine());

try
{
checked
{
result = (byte) (numOne + numTwo);
}
Console.WriteLine("Result : " + result);
}

catch (ArithmeticException ex)
{
Console.WriteLine(ex);
}
}
}
}

No comments: