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

3/6

Page

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

What will be the output of the following C# code snippet?
{
    try 
    {
        int a, b;
        b = 0;
        a = 10 / b;
        Console.WriteLine("A");
    }
    catch(ArithmeticException e) 
    {
        Console.WriteLine("B");        	
    }
    Console.ReadLine();
}

Select an option to see the answer and solution.

What will be the output of the following C# code snippet?
class Output 
{
    public static void main(String args[]) 
   {
       try 
       {
           int a = 0;
           int b = 5;
           int c = a / b - 5;
           Console.WriteLine("C");
       }
       finally 
       {
           Console.WriteLine("sharp");
       } 
   }
}

Select an option to see the answer and solution.

What will be the output of the following C# code?
{
    try 
    {
        int i, sum;
        sum = 10;
        for (i = -1 ;i < 3 ;++i) 
        {
            sum = (sum / i);
            Console.WriteLine(i);
        }
    }
    catch(ArithmeticException e) 
    {
        Console.WriteLine("0");
    }
    Console.ReadLine();
}

Select an option to see the answer and solution.

What will be the output of the following C# code?
{
    try 
    {
        int []a = {1, 2, 3, 4, 5};
        for (int i = 0; i < 5; ++i) 
        Console.WriteLine(a[i]);
        int x = (1 / Convert.ToInt32(0));
    }
    catch(IndexOutOfRangeException e) 
    {
        Console.WriteLine("A");        	
    }
    catch(ArithmeticException e) 
    {     	
        Console.WriteLine("B");
    }
    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 = 1;
            int b = 10 / a;
            try
            {
                if (a == 1)
                    a = a / a - a;
                if (a == 2)
                {
                    int[] c = { 1 };
                    c[8] = 9;
                }
            }
            finally
            {
                Console.WriteLine("A");
            }
       }
       catch (IndexOutOfRangeException e)
       {
            Console.WriteLine("B");
       }
       Console.ReadLine();
   }
}

Select an option to see the answer and solution.

Which of the following keywords is used by the calling function to guard against the exception that is thrown by called function?

Select an option to see the answer and solution.

What will be the output of the following C# code snippet?
{
    try 
    {
        int a, b;
        b = 0;
        a = 5 / b;
        Console.WriteLine("A");
    }
    catch(ArithmeticException e) 
    {
        Console.WriteLine("B");
    }
    finally
    {
        Console.WriteLine("C");
    }
    Console.ReadLine();
}

Select an option to see the answer and solution.

Which of the keywords are used for the block to be examined for exceptions?

Select an option to see the answer and solution.

Where the properties can be declared?

Select an option to see the answer and solution.

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

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 = 10;
            int b = 5;
            int c = a / b - 5;
            Console.WriteLine("Hi");
        }
        catch(Exception e) 
        {
            Console.WriteLine("hello");
        } 
    }
}

Select an option to see the answer and solution.

Choose the wrong statement about the properties used in C#.NET?

Select an option to see the answer and solution.

Which of these keywords is not a part of exception handling?

Select an option to see the answer and solution.

Which of the following is the object oriented way to handle run time errors?

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
        {
            throw new NullReferenceException("C");
            Console.WriteLine("A");
        }
        catch (ArithmeticException e) 
        {
            Console.WriteLine("B");
        }
        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 = 1 / a;
            Console.WriteLine(a);
        }
        catch (ArithmeticException e) 
        {
            Console.WriteLine("1");
        }
        Console.ReadLine();
    }
}

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 = 5;
           int b = 10;
           int c = b / a - 5;
           Console.WriteLine("Csharp");
       } 
   }
}

Select an option to see the answer and solution.

Choose the correct statement among the following?

Select an option to see the answer and solution.

Which of these keywords are used for generating an exception manually?

Select an option to see the answer and solution.

Choose the keyword which declares the indexer?

Select an option to see the answer and solution.