using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace UserDefinedException
{
class Program
{
static void Main(string[] args)
{
Temperature temp = new Temperature();
try
{
temp.showTemp();
}
catch (ZeroException e)
{
Console.WriteLine("ZeroException: {0}", e.Message);
}
Console.ReadKey();
}
}
}
public class ZeroException : Exception
{
public ZeroException(string message): base(message)
{
}
}
public class Temperature
{
public void showTemp()
{
double cel;
Console.WriteLine("Enter the temperature to convert from Fahrenheit to Celsius");
double fah = Double.Parse(Console.ReadLine());
cel = (fah - 32) * 5 / 9;
Console.WriteLine("The converted temperature is" + cel + " degrees Celsius");
if (fah == 0)
{
throw (new ZeroException("Zero Temperature found"));
}
else
{
Console.WriteLine("Temperature: {0}", cel);
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace UserDefinedException
{
class Program
{
static void Main(string[] args)
{
Temperature temp = new Temperature();
try
{
temp.showTemp();
}
catch (ZeroException e)
{
Console.WriteLine("ZeroException: {0}", e.Message);
}
Console.ReadKey();
}
}
}
public class ZeroException : Exception
{
public ZeroException(string message): base(message)
{
}
}
public class Temperature
{
public void showTemp()
{
double cel;
Console.WriteLine("Enter the temperature to convert from Fahrenheit to Celsius");
double fah = Double.Parse(Console.ReadLine());
cel = (fah - 32) * 5 / 9;
Console.WriteLine("The converted temperature is" + cel + " degrees Celsius");
if (fah == 0)
{
throw (new ZeroException("Zero Temperature found"));
}
else
{
Console.WriteLine("Temperature: {0}", cel);
}
}
}
No comments:
Post a Comment