0% found this document useful (0 votes)
6 views1 page

Exception Handling - Division

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views1 page

Exception Handling - Division

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

using System;

namespace ExceptionHandlingDemo
{
class Program
{
static void Main(string[] args)
{
try
{
Console.WriteLine("Enter first integer: ");
int num1 = int.Parse(Console.ReadLine());
Console.WriteLine("Enter second integer: ");
int num2 = int.Parse(Console.ReadLine());
int result = num1 / num2;
Console.WriteLine($"Result: {result}");
}
catch (DivideByZeroException)
{
Console.WriteLine("Error: Cannot divide by zero.");
}
catch (Exception ex)
{
Console.WriteLine("Error: " + ex.Message);
}
Console.ReadLine();
}
}
}

You might also like