Search Placementyogi.com
 

C# Exception Handling - Advanced .NET Objective Questions

1

What is the output of the following C# program?

using System;
namespace PlacementYogi
{
    class ExceptionHandling
    {
        static void Main(string[] args)
        {
            int i;
            int[] myArray = new int[5];
            try
            {
                i = Convert.ToInt32("A");
                myArray[i] = 10;
            }
            catch (FormatException e)
            {
                Console.WriteLine("Incorrect Format Exception");
            }
            catch (IndexOutOfRangeException e)
            {
                Console.WriteLine("Index out of bounds Exception");
            }
            catch (Exception e)
            {
                Console.WriteLine("General Exceptin");
            }
        }
    }
}
A.

Incorrect Format Exception

B.

Index out of bounds Exception

C.

General Exception

D.

None of the above

See Answer & Explanation Lets Discuss
Correct answer is : A
Explanation

A is a string which cannot be stored in a variable of type int (here i) so FormatException occurs.

 
2

What is the output of the following C# program?

using System;
namespace PlacementYogi
{
    class ExceptionHandling
    {
        static void Main(string[] args)
        {
            int i;
            int[] myArray = new int[5];
            try
            {
                i = Convert.ToInt32('A');
                myArray[i] = 10;
            }
            catch (FormatException e)
            {
                Console.WriteLine("Incorrect Format Exception");
            }
            catch (IndexOutOfRangeException e)
            {
                Console.WriteLine("Index out of bounds Exception");
            }
            catch (Exception e)
            {
                Console.WriteLine("General Exceptin");
            }
        }
    }
}
A.

Incorrect Format Exception

B.

Index out of bounds Exception

C.

General Exception

D.

None of the above

See Answer & Explanation Lets Discuss
Correct answer is : B
Explanation

ASCII value of A which is 65, is stored to i but myArray does not have index as 65 hence IndexOutOfRangeException occurs.

 
3

What is the output of the following C# program?

using System;
namespace PlacementYogi
{
    class ExceptionHandling
    {
        static void Main(string[] args)
        {
            int i,j=10;
            int[] myArray = new int[5];
            try
            {
                i = Convert.ToInt32("1");
                myArray[i] = 10;
                Console.Write(myArray[1]/(j-10));
            }
            catch (FormatException e)
            {
                Console.WriteLine("Incorrect Format Exception");
            }
            catch (IndexOutOfRangeException e)
            {
                Console.WriteLine("Index out of bounds Exception");
            }
            catch (Exception e)
            {
                Console.WriteLine("General Exception");
            }
            finally
            {
                Console.WriteLine("Inside finally block");
            }
        }
    }
}
A.

Inside finally block

B.

Incorrect Format Exception

Inside finally block

C.

Index out of bounds Exception

Inside finally block

D.

General Exceptin

Inside finally block

E.

None of these

See Answer & Explanation Lets Discuss
Correct answer is : D
Explanation

Here DivideByZeroException will occur which will be handled by Exception class because DivideByZeroException is not used in this program. finally block will be executed every time irrespective of exception occurred. Hence option D is correct.

 
 

Banner to LogicGuns.com

Hide Page Information

C# Exception Handling - Advanced .NET Objective Questions and Answers with Explanation

Here you can find Advanced level C# Exception Handling interview questions with answers and explanation.

Why Exception Handling in C#?

In this section you can learn and practice different types of Advanced level questions with answers on exception handling to improve your skills in order to face the interviews,competitive examinations and various entrance tests with full confidence.

Where can I get C# Exception Handling Advanced Questions and Answers with Explanation?

PlacementYogi provides you lots of fully solved advanced level exception handling questions and answers with explanation. Fully solved examples with detailed answer description, explanation are given and it would be easy to understand. All students, freshers can download quiz questions with answers as PDF files and eBooks.

Where can I get Advanced Level C# Exception Handling Interview Questions and Answers (objective type, multiple choice)?

Here you can find objective type Advanced exception handling questions and answers for interview and entrance examination. Multiple choice and TRUE or FALSE type and YES or NO type questions are also provided.