Lab_Sheet_5_Exception Handling
Lab_Sheet_5_Exception Handling
Exception Handling
1. Developer is writing code for dividing two numbers. If the user enters 0 in the second
number, an exception should be raised. Handle the exception with the appropriate
code.
namespace ConsoleApp10
{
internal class Program
{
static void Main(string[] args)
{
int a, b;
}
}
2. Admin executive of the university is entering the university name for the students. If
he enters the name wrongly, exception should be raised.
namespace ExceptionHandlingDemo
{
internal class Collegename
{
static void Main()
{
string s;
Console.WriteLine("Enter your university name");
try
{
s = Console.ReadLine();
if (s.ToUpper() == "PRESIDENCY")
{
Console.WriteLine("Welcome");
}
else
{
throw new Exception("You have entered wrong input");
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
Console.ReadKey();
}
}
}
Assessment 5a:
Raise the exception not eligible for voting if the age is less than 18.
Assessment 5b:
A University has decided promotion criteria for students. According to criteria a student
cannot be promoted to next academic year if he has less than 4.5 CGPA. A developer is
trying to implement this situation using exception handling by reading the necessary
details of all 6 subjects
Hint: CGPA = (Percentage / 9.5)