0% found this document useful (0 votes)
4 views2 pages

Program

The document is a C# program that demonstrates exception handling with various try-catch blocks. It includes methods for printing numbers from a list and reading user input to create a 'Person' object. The program handles exceptions such as empty lists, format errors, and index out of bounds, while providing feedback to the user and indicating the process's completion status.

Uploaded by

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

Program

The document is a C# program that demonstrates exception handling with various try-catch blocks. It includes methods for printing numbers from a list and reading user input to create a 'Person' object. The program handles exceptions such as empty lists, format errors, and index out of bounds, while providing feedback to the user and indicating the process's completion status.

Uploaded by

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

using System;

using System.Collections.Generic;

namespace _12_04_PREPARATION_11V_11E
{
public class Program
{
public static void PrintNumbers(List<int> repo)
{
if(repo.Count < 0)
{
throw new Exception("Empty repo");
}
}
public static void Main(string[] args)
{
List<int> list = new List<int>();
try
{
Program.PrintNumbers(list);
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
}
try
{
int number = int.Parse("Invalid value");
}
catch(FormatException ex)
{
Console.WriteLine(ex.Message);
}

bool flag = false;


Console.WriteLine("Enter First Name, Last Name, Age:"); // Write to
console Console.WriteLine()
try
{
string[] input = Console.ReadLine().Split(" "); // Read on line
line all the input
Person person = new Worker(input[0], input[1],
int.Parse(input[2]));
Console.WriteLine(person.ToString()); // Write to console
Console.WriteLine()
flag = true;
}
catch (IndexOutOfRangeException ex)
{
Console.WriteLine("Index out of bounds (range) exception");
}
catch(CustomExceptions ex )
{

}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
finally
{
Console.WriteLine("Process ended with flag {0}", flag);
}
}
}
}

You might also like