My Report

C# Exception Handling Test – 3


Correct Answer: 2 points | Wrong: -1 point
Grades: A* (100% score) | A (80%-99%) | B (60%-80%) | C (40%-60%) | D (0%-40%)
advertisement

1. What will be the output of the following C# code snippet?

 class program
 {
     public static void Main(string[] args)
     {
         try
         {
             throw new NullReferenceException("C");
             Console.WriteLine("A");
         }
         catch (ArithmeticException e) 
         {
             Console.WriteLine("B");
         }
         Console.ReadLine();
     }
 }

2. Which of these classes is related to all the exceptions that are explicitly thrown?

3. What will be the output of the following C# code snippet?

 class Program
 {
     public static void Main(string[] args)
     {
         try
         {
             int a = 1;
             int b = 10 / a;
             try
             {
                 if (a == 1)
                     a = a / a - a;
                 if (a == 2)
                 {
                     int[] c = { 1 };
                     c[8] = 9;
                 }
             }
             finally
             {
                 Console.WriteLine("A");
             }
        }
        catch (IndexOutOfRangeException e)
        {
             Console.WriteLine("B");
        }
        Console.ReadLine();
    }
 }

4. Which of these exceptions will occur if we try to access the index of an array beyond its length?

5. Which of the following keywords is used by the calling function to guard against the exception that is thrown by called function?

6. Which of these clauses will be executed even if no exceptions are found?

7. What will be the output of the following C# code snippet?

 class Program
 {
     public static void Main(string[] args)
     {
         try
         {
             int a = args.Length;
             int b = 10 / a;
             Console.WriteLine(a);
             try
             {
                 if (a == 1)
                 a = a / a - a;
                 if (a == 2)
                 {
                     int[] c = { 1 };
                     c[8] = 9;
                 }
             }
             catch (IndexOutOfRangeException e)
             {
                 Console.WriteLine("TypeA");
             }
         }
         catch (ArithmeticException e)
         {
             Console.WriteLine("TypeB");
         }
         Console.ReadLine();
     }
 }

8. Which of these exceptions handles the divide by zero error?

9. A single try block must be followed by which of these?

10. What will be the output of the following C# code snippet?

   class program
   {
       public static void Main(string[] args)
       {
           try 
           {
               int a = args.Length;
               int b = 1 / a;
               Console.WriteLine(a);
           }
           catch (ArithmeticException e) 
           {
               Console.WriteLine("1");
           }
           Console.ReadLine();
       }
   }

 

Start practicing “1000 MCQs on C#”, and once you are ready, you can take tests on all topics by attempting our “C# Test Series”.

Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.