Vidyalelo
C# Programming · all questions

Exception Handling in C Sharp
practice.

Practice every MCQ with options. Use Show answers when you want the correct option and solution.

107

Questions

5/6

Page

Pick an option on a question to see the right answer and solution.

A single try block must be followed by which of these?

Select an option to see the answer and solution.

Choose the correct statement about properties describing the indexers?

Select an option to see the answer and solution.

Which of these exceptions handles the divide by zero error?

Select an option to see the answer and solution.

Choose the correct statements about write-only properties in C#.NET?

Select an option to see the answer and solution.

Select the correct statement about an Exception?

Select an option to see the answer and solution.

What will be the output of the following C# code?
class Output 
{
    public static void main(String args[]) 
    {

        try 
        {
            int a = 9;
            int b = 5;
            int c = a / b - 5;
            Console.WriteLine("Hello");
        }
        catch(Exception e) 
        {
            Console.WriteLine("C");
        } 
        finally 
        {
            Console.WriteLine("sharp");
        } 
    }
}

Select an option to see the answer and solution.

When is no exception thrown at runtime then who will catch it?

Select an option to see the answer and solution.

Which among the following is considered as .NET Exception class?

Select an option to see the answer and solution.

What will be the output of the following C# code?
public  static void Main(string[] args)
{
    try
    {
        int a, b, c = 5;
        b = 0;
        a = c / b;
        Console.WriteLine("A");
    }
    catch (ArithmeticException e)
    {
        int c = 5;
        int i = 10;
        int z = 2 * c - i;
        Console.WriteLine("B");
        Console.WriteLine(z);
    }
    Console.ReadLine();
}

Select an option to see the answer and solution.

What will be the output of the following C# code?
static void Main(string[] args)
{            
    try 
    {
        Console.WriteLine("csharp" + " " + 1/Convert.ToInt32(0));
    }
    catch(ArithmeticException e) 
    {
        Console.WriteLine("Java");        	
    }
    Console.ReadLine();
}

Select an option to see the answer and solution.

Choose the operator/operators which is/are not used to access the [] operator in indexers?

Select an option to see the answer and solution.

Choose the correct statement which makes exception handling work in C#.NET?

Select an option to see the answer and solution.

Choose the statement which is incorrect?

Select an option to see the answer and solution.

Which among the following is NOT an exception?

Select an option to see the answer and solution.

What is the use of try & catch?

Select an option to see the answer and solution.

Which of these keywords is used to manually throw an exception?

Select an option to see the answer and solution.

Choose the correct option among the following indexers which correctly allows to index in same way as an array?

Select an option to see the answer and solution.

What will be the output of the following C# code?
class number
{
    int length = 50;
    public int number1
    {
        get
        {
            return length;
        }
        set
        {
            length = value;
        }
    }
}
class Program
{
    public static void Main(string[] args)
    {
        number p = new number();
        p.number1 = p.number1 + 40;
        int k = p.number1 * 3 / 9;
        Console.WriteLine(k);
        Console.ReadLine();
    }
}

Select an option to see the answer and solution.

What will be the output of the following C# code snippet?
class Program
{
    public static void Main(string[] args)
    {
        try
        {
            int a = args.Length;
            int b = 10 / a;
            Console.WriteLine(a);
            try
            {
                if (a == 1)
                a = a / a - a;
                if (a == 2)
                {
                    int[] c = { 1 };
                    c[8] = 9;
                }
            }
            catch (IndexOutOfRangeException e)
            {
                Console.WriteLine("TypeA");
            }
        }
        catch (ArithmeticException e)
        {
            Console.WriteLine("TypeB");
        }
        Console.ReadLine();
    }
}

Select an option to see the answer and solution.

Which of these classes is related to all the exceptions that are explicitly thrown?

Select an option to see the answer and solution.