C# Exception Handling Aptitude Questions and Answers | Set 4

C# Exception Handling Aptitude Questions | Set 4: This section contains aptitude questions and answers on C# Exception Handling.
Submitted by Nidhi, on April 16, 2020

1) Which is not a valid keyword used in the context of exception handling?
  1. try
  2. catch
  3. final
  4. finally

2) Which is a valid keyword used in the context of exception handling?
  1. through
  2. throw
  3. final
  4. caught

3) There are following statements are given below, which is correct about throw in C#.NET?
  1. The throw keyword is not supported in C#.NET
  2. The throw keyword is used to throw an exception object programmatically
  3. The throw keyword is used in older versions of the .NET framework
  4. The throw keyword is mandatory to use with the try block

4) What is the correct output of the given code snippet?
using System;

namespace my_namespace
{
    class program
    {
        static void Main(string[] args)
        {
            int a = 0;
            int b = 10;
            int c = 0;

            try
            {
                c = b / a;
            }
            catch (DivideByZeroException d)
            {
                Console.WriteLine("Divide by zero exception occurred");
            }
        }
    }
}
  1. Divide by zero exception occurred
  2. Syntax error
  3. Linker error
  4. No output

5) In the given code snippet finally block will execute or not?
using System;

namespace my_namespace
{
    class program
    {
        static void Main(string[] args)
        {
            int a = 0;
            int b = 10;
            int c = 0;

            try
            {
                c = b / a;
            }
            finally
            {
                Console.WriteLine("Finally executed");
            }
        }
    }
}
  1. Yes, finally will execute
  2. No, finally will not execute





Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.