Home / CSE MCQs / C#.Net MCQs :: C# Exception Handling

CSE MCQs :: C#.Net MCQs

  1. What will be the output of given 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. A.
    A
    B.
    B
    C.
    Compile time error
    D.
    Runtime error

    View Answer

    Workspace

    Discuss Discuss in Forum


  3. What will be the output of the given 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. A.
    A
    B.
    B
    C.
    AB
    D.
    BA

    View Answer

    Workspace

    Discuss Discuss in Forum


  5. Which of these keywords is not a part of exception handling?
  6. A.
    try
    B.
    finally
    C.
    thrown
    D.
    catch

    View Answer

    Workspace

    Discuss Discuss in Forum


  7. Which of these keywords must be used to monitor exceptions?
  8. A.
    try
    B.
    finally
    C.
    throw
    D.
    catch

    View Answer

    Workspace

    Discuss Discuss in Forum


  9. What would be the output of following code snippet?

    {
         try 
         {
             int a, b;
             b = 0;
             a = 5 / b;
             Console.WriteLine("A");
         }
         catch(ArithmeticException e) 
         {
             Console.WriteLine("B");
         }
         finally
         {
             Console.WriteLine("C");
         }
         Console.ReadLine();
     }
  10. A.
    A
    B.
    B
    C.
    B C
    D.
    Run time error

    View Answer

    Workspace

    Discuss Discuss in Forum


  11. What would be the output of given code snippet?

    class Program
     {
         static void Main(string[] args)
         {
             int i;
             int v = 40;
             int[] x = new int[5];
             try
             {
                 Console.WriteLine(" Enter the number: ");
                 index = Convert.ToInt32(Console.ReadLine());
                 x[index] = v;
             }
             catch(Exception e)
             {
                 Console.WriteLine("Exception occured");
             }
             Console.WriteLine("Program executed");
         }
     }
  12. A.
    Exception occured
    B.
    Program executed
    C.
    Exception occured Program executed
    D.
    Program executed Exception occured

    View Answer

    Workspace

    Discuss Discuss in Forum


  13. Choose the correct statement among the following?
  14. A.
    A property can be a static member whereas an indexer is always an instance member
    B.
    A get accessor of a property corresponds to a method with no parameters whereas get accessor of an indexer corresponds to a method with the same formal parameters lists as the indexer
    C.
    It is an error for indexer to declare a local variable with the same name as indexer parameters
    D.
    All of the mentioned

    View Answer

    Workspace

    Discuss Discuss in Forum


  15. Consider a class maths and we had a property called as sum.b is a reference to a maths object and we want the statement b.sum = 10 to fail.Which of the following is the correct solution to ensure this functionality?
  16. A.
    Declare sum property with both get and set accessors
    B.
    Declare sum property with only get accessor
    C.
    Declare sum property with get, set and normal accessors
    D.
    None of the mentioned

    View Answer

    Workspace

    Discuss Discuss in Forum


  17. Consider a class maths and we had a property called as sum.b which is the reference to a maths object and we want the statement Console.WriteLine(b.sum)to fail.Which among the following is the correct solution to ensure this functionality?
  18. A.
    Declares sum property with only get accessor
    B.
    Declares sum property with only set accessor
    C.
    Declares sum property with both set and get accessor
    D.
    Declares sum property with both set, get and normal accessor

    View Answer

    Workspace

    Discuss Discuss in Forum


  19. Which of these keywords are used for the block to handle the exceptions generated by try block?
  20. A.
    try
    B.
    catch
    C.
    throw
    D.
    check

    View Answer

    Workspace

    Discuss Discuss in Forum