C# Exception MCQs

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");
}

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");
}

Question 6: 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(IndexOutOfRangeException  ex){
        Console.WriteLine("Index error occurred!");
    }
    catch(NullReferenceException  ex){
        Console.WriteLine("Null error occurred!");
    }
    catch(Exception ex){
        Console.WriteLine("Error occurred!");
    }
}

Question 7: 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!");
	}
	catch(IndexOutOfRangeException  ex){
        Console.WriteLine("Index error occurred!");
    }
    catch(NullReferenceException  ex){
        Console.WriteLine("Null error occurred!");
    }
}

Question 8: 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!");
    }
    finally
    {
        Console.WriteLine("Executing finally block");
    }
	
	Console.WriteLine("Executing remaining program.");
}

Question 9: Select the correct output of the following program?

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

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

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