csharp Exception Questions & Answers

Question 1: Which of the following is the base class for all types of exceptions?

Question 2: Which of the following statement is TRUE?

Question 3: What will be the output of the following program?

public static void Main()
{
    int[] arr = {1, 2, 3, 4, 5};
    Console.Write(arr[10]);
    Console.WriteLine("End of Program");
}
ADVERTISEMENT

Question 4: What will be the output of the following program?

public static void Main()
{
    int[] arr = {1, 2, 3, 4, 5};
    
    try
    {
        Console.Write(arr[10]);
    }    
    catch(Exception ex)
    {
        Console.WriteLine("Error occurred!");
    }

    Console.WriteLine("Execute remaining program..");		
}

Question 5: What will be the output of the following program?

public static void Main()
{
    int[] arr = {1, 2, 3, 4, 5};
	try
    {
        Console.Write(arr[5]);
    }    
    catch(NullReferenceException  ex)
    {
        Console.WriteLine("Error occurred!");
    }
	Console.WriteLine("Execute remaining program");
}