adplus-dvertising

Welcome to the Indexers and Exception Handling MCQs Page

Dive deep into the fascinating world of Indexers and Exception Handling with our comprehensive set of Multiple-Choice Questions (MCQs). This page is dedicated to exploring the fundamental concepts and intricacies of Indexers and Exception Handling, a crucial aspect of C# programming. In this section, you will encounter a diverse range of MCQs that cover various aspects of Indexers and Exception Handling, from the basic principles to advanced topics. Each question is thoughtfully crafted to challenge your knowledge and deepen your understanding of this critical subcategory within C# programming.

frame-decoration

Check out the MCQs below to embark on an enriching journey through Indexers and Exception Handling. Test your knowledge, expand your horizons, and solidify your grasp on this vital area of C# programming.

Note: Each MCQ comes with multiple answer choices. Select the most appropriate option and test your understanding of Indexers and Exception Handling. You can click on an option to test your knowledge before viewing the solution for a MCQ. Happy learning!

Indexers and Exception Handling MCQs | Page 3 of 13

Explore more Topics under C# programming

Q21.
Which of the following statements are correct about exception handling in C#.NET?

1. If our program does not catch an exception then the .NET CLR catches it.
2. It is possible to create user-defined exceptions.
3. All types of exceptions can be caught using the Exception class.
4. CLRExceptions is the base class for all exception classes.
5. For every try block there must be a corresponding finally block.
Discuss
Answer: (b).1, 2 and 3 only
Q22.
Which of the following statements are correct about the exception reported below?

Unhandled Exception: System.lndexOutOfRangeException:
Index was outside the bounds of the array:
at CompSciBitsConsoleApplication.MyProgram.SetVal(Int32 index, Int32 val) in
D:\Sample\CompSciBitsConsoleApplication\MyProgram.cs:line 26
at CompSciBitsConsoleApplication.MyProgram.Main(String[] args) in
D:\Sample\CompSciBitsConsoleApplication\MyProgram.cs:line 20

1. The CLR failed to handle the exception.
2. The class MyProgram belongs to the namespace MyProgram.
3. The function SetVal() was called from Main() in line number 20.
4. The exception occurred in line number 26 in the function SetVal()
5. The runtime exception occurred in the project CompSciBitsConsoleApplication.
Discuss
Answer: (c).3, 4 and 5 only
Q23.
Which of the following is the Object Oriented way of handling run-time errors?
Discuss
Answer: (c).Exceptions
Q24.
Which of the following statements is correct about the C#.NET program given below if a value "6" is input to it?

using System;
namespace CompSciBitsConsoleApplication
{
    class MyProgram
    {
        static void Main(string[] args)
        {
            int index; 
            int val = 44;
            int[] a = new int[5];
            try
            {
                Console.Write("Enter a number:");
                index = Convert.Tolnt32(Console.ReadLine());
                a[index] = val;
            }
            catch(FormatException e)
            {
                Console.Write("Bad Format");
            }
            catch(IndexOutOfRangeException e)
            {
                Console.Write("Index out of bounds");
            }
            Console.Write("Remaining program");
        }
    }
}
Discuss
Answer: (a).It will output: Index out of bounds Remaining program
Q25.
Which of the following statements are correct about the exception reported below?

Unhandled Exception: System.lndexOutOfRangeException:
Index was outside the bounds of the array.
at CompSciBitsConsoleApplication.Program.Main(String[] args) in
D:\ConsoleApplication\Program.cs:line 14

1.The program did not handle an exception called IndexOutOfRangeException.
2. The program execution continued after the exception occurred.
3. The exception occurred in line number 14.
4. In line number 14, the program attempted to access an array element which was beyond the bounds of the array.
5. The CLR could not handle the exception.
Discuss
Answer: (d).1, 3 and 4 only
Q26.
Which of the following statements are correct about exception handling in C#.NET?

1. try blocks cannot be nested.
2. In one function, there can be only one try block.
3. An exception must be caught in the same function in which it is thrown.
4. All values set up in the exception object are available in the catch block.
5. While throwing a user-defined exception multiple values can be set in the exception, object.
Discuss
Answer: (d).4 and 5 only
Q27.
Exceptions can be thrown even from a constructor, whereas error codes cannot be returned from a constructor.
Discuss
Answer: (a).True
Q28.
Which of the following statements is correct about the C#.NET program given below if a value "6" is input to it?

using System;
namespace CompSciBitsConsoleApplication
{
    class MyProgram
    {
        static void Main (string[] args)
        {
            int index; 
            int val = 66; 
            int[] a = new int[5]; 
            try
            {
                Consote.Write("Enter a number: "); 
                index = Convert.ToInt32(Console.ReadLine()); 
                a[index] = val;
            }
            catch(Exception e)
            {
                Console.Write("Exception occurred ");
            }
            Console.Write("Remaining program ");
        }
    }
}
Discuss
Answer: (c).It will output: Exception occurred Remaining program
Q29.
Which of the following statements is correct about the C#.NET program given below if a value "ABCD" is input to it?

using System;
namespace CompSciBitsConsoleApplication
{
    class MyProgram
    {
        static void Main(string[] args)
        {
            int index; 
            int val = 55; 
            int[] a = new int[5]; 
            try
            {
                Console.Write("Enter a number: ");
                index = Convert.ToInt32(Console.ReadLine());
                a[index] = val;
            }
            catch(FormatException e)
            {
                Console.Write("Bad Format ");
            }
            catch(IndexOutOfRangeException e)
            {
                Console.Write("Index out of bounds ");
            }
            Console.Write("Remaining program ");
        }
    }
}
Discuss
Answer: (d).It will output: Bad Format Remaining program
Q30.
All code inside finally block is guaranteed to execute irrespective of whether an exception occurs in the protected block or not.
Discuss
Answer: (a).True

Suggested Topics

Are you eager to expand your knowledge beyond C# programming? We've curated a selection of related categories that you might find intriguing.

Click on the categories below to discover a wealth of MCQs and enrich your understanding of Computer Science. Happy exploring!