C# Exception Handling Aptitude Questions and Answers | Set 5

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

1) Is it mandatory to use finally block with try and catch?
  1. Yes
  2. No

2) 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 (Exception d)
            {
                Console.Write("Divide by zero exception occurred, ");
            }
            finally
            {
                Console.WriteLine("Finally executed");
            }
        }
    }
}
  1. Divide by zero exception occurred
  2. Divide by zero exception occurred, Finally executed
  3. Syntax error
  4. Linker error

3) In C#.NET, "Exception" is the superclass of all types of exceptions classes.
  1. Yes
  2. No

4) There are following statements are given below, which of them are correct about the checked keyword in C#.NET?
  1. The checked is not any keyword in C#.NET
  2. We can use the unchecked keyword, but we cannot use the checked keyword in C#.NET
  3. The checked keyword is used to check the overflow and conversion of integral type values
  4. The checked keyword is used in older versions of the .NET framework

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

namespace my_namespace
{
    class program
    {
        static void Main(string[] args)
        {
            checked
            {
                int my_val = int.MaxValue;
                Console.WriteLine(my_val + 3);
            }  
        }
    }
}
  1. -2147483646
  2. Syntax error
  3. Linker error
  4. Overflow exception





Comments and Discussions!

Load comments ↻





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