C# Questions & Answers – Fundamentals of Exception Handling

This section of our 1000+ C# multiple choice questions focuses on fundamentals of the exception handling in C# Programming Language.

1. Which among the following is NOT an exception?
a) Stack Overflow
b) Arithmetic Overflow or underflow
c) Incorrect Arithmetic Expression
d) All of the mentioned
View Answer

Answer: c
Explanation: None.

2. Which among the following is considered as .NET Exception class?
a) Exception
b) StackUnderflow Exception
c) File bound Exception
d) All of the mentioned
View Answer

Answer: b
Explanation: None.

3. Which of the following is the object oriented way to handle run time errors?
a) Error codes
b) HERRESULT
c) OnError
d) Exceptions
View Answer

Answer: d
Explanation: None.
advertisement
advertisement

4. Select the statements which describe the correct usage of exception handling over conventional error handling approaches?
a) As errors can be ignored but exceptions cannot be ignored
b) Exception handling allows separation of program’s logic from error handling logic making software more reliable and maintainable
c) try – catch – finally structure allows guaranteed cleanup in event of errors under all circumstances
d) All of the mentioned
View Answer

Answer: d
Explanation: None.

5. Select the correct statement about an Exception?
a) It occurs during loading of program
b) It occurs during Just-In-Time compilation
c) It occurs at run time
d) All of the mentioned
View Answer

Answer: c
Explanation:None.

6. Which of these keywords is not a part of exception handling?
a) try
b) finally
c) thrown
d) catch
View Answer

Answer: c
Explanation: Exception handling is managed via 5 keywords – try, catch, throws, throw and finally.

7. Which of these keywords must be used to monitor exceptions?
a) try
b) finally
c) throw
d) catch
View Answer

Answer: a
Explanation: None.
advertisement

8. Which of these keywords is used to manually throw an exception?
a) try
b) finally
c) throw
d) catch
View Answer

Answer: c
Explanation: None.

9. What will be the output of the following C# code?

advertisement
  1.  class program
  2.  {
  3.      static void main(string[] args)
  4.      {
  5.          int i = 5;
  6.          int v = 40;
  7.          int[] p = new int[4];
  8.          try
  9.          {
  10.              p[i] = v;
  11.          }
  12.          catch(IndexOutOfRangeException e)
  13.          {
  14.              Console.WriteLine("Index out of bounds");
  15.          }
  16.          Console.WriteLine("Remaining program");
  17.      }
  18.  }

a) value 40 will be assigned to a[5];
b)

The output will be :
Index out of bounds
Remaining program

c)

The output will be :
Remaining program

d) None of the mentioned
View Answer

Answer: b
Explanation:None.

10. What will be the output of the following C# code?

  1.  static void Main(string[] args)
  2.  {            
  3.      try 
  4.      {
  5.          Console.WriteLine("csharp" + " " + 1/Convert.ToInt32(0));
  6.      }
  7.      catch(ArithmeticException e) 
  8.      {
  9.          Console.WriteLine("Java");        	
  10.      }
  11.      Console.ReadLine();
  12.  }

a) csharp
b) java
c) run time error
d) csharp 0
View Answer

Answer: b
Explanation: 1 / 0, hence system out of flow exception error.

11. Which of the following is the wrong statement about exception handling in C#.NET?
a) finally clause is used to perform cleanup operations of closing network and database connections
b) a program can contain multiple finally clauses
c) the statement in final clause will get executed no matter whether an exception occurs or not
d) all of the mentioned
View Answer

Answer: b
Explanation: None.

12. What will be the output of the following C# code?

  1.   class Program
  2.   {
  3.       static void Main(string[] args)
  4.       {            
  5.           try 
  6.           {
  7.               Console.WriteLine("csharp" + " " + 1/0);
  8.           }
  9.           finally
  10.           {
  11.               Console.WriteLine("Java");        	
  12.           }
  13.           Console.ReadLine();
  14.       }
  15.   }

a) csharp 0
b) Run time Exception generation
c) Compile time error
d) Java
View Answer

Answer: b
Explanation: Run time Error of division by zero.

Sanfoundry Global Education & Learning Series – C# Programming Language.
Here’s the list of Best Books in C# Programming Language.

To practice all features of C# programming language, here is complete set on 1000+ Multiple Choice Questions and Answers on C#

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.