C# Questions & Answers on Fundamentals of Exception Handling for Freshers

https://www.computersprofessor.com/2018/07/c-questions-answers-on-fundamentals-of.html
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
Answer: c
2. Which among the following is considered as .NET Exception class?
a) Exception
b) StackUnderflow Exception
c) File Found Exception
d) All of the mentioned
Answer: b, c
3. Which of the following is the object oriented way to handle run time errors?
a) Error codes
b) HERRESULT
c) OnError
d) Exceptions
Answer: d
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
Answer: d
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
Answer: c
6. Which of these keywords is not a part of exception handling?
a) try
b) finally
c) thrown
d) catch
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
Answer: a
8. Which of these keywords is used to manually throw an exception?
a) try
b) finally
c) throw
d) catch
Answer: c
9. Choose the correct output for the given set of code:
class program
{
static void main(string[] args)
{
int i = 5;
int v = 40;
int[] p = new int[4];
try
{
p[i] = v;
}
catch(IndexOutOfRangeException e)
{
Console.WriteLine("Index out of bounds");
}
Console.WriteLine("Remaining program");
}
}
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
b) The output will be :
Index out of bounds
Remaining program
c) The output will be :
Remaining program
d) None of the mentioned
Answer: b
10. Choose the correct output for the given set of code:
static void Main(string[] args)
{
try
{
Console.WriteLine("csharp" + " " + 1/Convert.ToInt32(0));
}
catch(ArithmeticException e)
{
Console.WriteLine("Java");
}
Console.ReadLine();
}
a) csharp
b) java
c) run time error
d) csharp 0
b) java
c) run time error
d) csharp 0
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
Answer: b
12. Choose the correct output for given set of code:
class Program
{
static void Main(string[] args)
{
try
{
Console.WriteLine("csharp" + " " + 1/0);
}
finally
{
Console.WriteLine("Java");
}
Console.ReadLine();
}
}
a) csharp 0
b) Run time Exception generation
c) Compile time error
d) Java
b) Run time Exception generation
c) Compile time error
d) Java
Answer: b
Explanation: Run time Error of division by zero.