C# Programming - Exception Handling

Exercise : Exception Handling - General Questions
  • Exception Handling - General Questions
11.
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.
1 only
1 and 2 only
3 only
4 and 5 only
All of the above
Answer: Option
Explanation:
No answer description is available. Let's discuss.

12.
Exceptions can be thrown even from a constructor, whereas error codes cannot be returned from a constructor.
True
False
Answer: Option
Explanation:
No answer description is available. Let's discuss.

13.
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 IndiabixConsoleApplication
{
    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 ");
        }
    }
}
It will output: Exception occurred
It will output: Remaining program
It will output: Exception occurred Remaining program
It will output: Remaining program Exception occurred
The value 66 will get assigned to a[6].
Answer: Option
Explanation:
No answer description is available. Let's discuss.

14.
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 IndiabixConsoleApplication
{
    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 ");
        }
    }
}
It will output: Bad Format
It will output: Remaining program
It will output: Index out of bounds
It will output: Bad Format Remaining program
It will output: Index out of bounds Remaining program
Answer: Option
Explanation:
No answer description is available. Let's discuss.

15.
All code inside finally block is guaranteed to execute irrespective of whether an exception occurs in the protected block or not.
True
False
Answer: Option
Explanation:
No answer description is available. Let's discuss.