Select chapter



Basics (2.papers)
Data Types (2.papers)
enums (2.papers)
OOPS (4.papers)
Arrays (1.papers)
Structs (2.papers)
Properties (2.papers)
Strings (2.papers)
Interfaces (1.papers)
Constructors (2.papers)
Ref-Out-Keywords (1.papers)
Collections (2.papers)
Generics (1.papers)
Hide

Sponsored Links


  

c# exception handling interview questions and answers

1
What is an exception in Csharp ?
  1. An exception is a runtime error.
  2. An exception is a compilation error.
  3. An exception is a runtime error which will be occuring when clr encounters an un-known situation.
  4. options 1 and 3 are correct.
Show Answer
Share Facebook gmail Twitter
2
How to handle exceptions in csharp ?
  1. Using try catch blocks.
  2. Using try finally blocks .
  3. Using catch blocks alone.
  4. None of the above.
Show Answer
Share Facebook gmail Twitter
3
What will happen if exception is not handled in the program ?
  1. Compiler will not allow the programmer to run the code.
  2. Clr will terminate the program execution where it identifies an exception.
  3. Clr will not show the output but program will be executed successfully.
  4. None of the above.
Show Answer
Share Facebook gmail Twitter
4
What is the use of a try and catch blocks in c# ?
  1. Within try block suspected code must be written and in catch block we must write exception handling code.
  2. Within try block we must write exception handling code and in catch block we must write suspected code.
  3. In try block we must write suspected code and in catch block no code must be written.
  4. None of the above.
Show Answer
Share Facebook gmail Twitter
5
What is the use of finally block in C# ?
  1. The code present in finally block is executed only when the catch or try block is having return statements.
  2. The code present in finally block is executed only when catch block is having return statement.
  3. The code present in finally block is always executed irrespective of return statements in try or catch blocks.
  4. finally blocks are used for returning custom exceptions back to callers.
Show Answer
Share Facebook gmail Twitter
6
Is it possible to write return statements in try catch and finally blocks ?
  1. Yes, we can return data using return statements.
  2. It is not possible to write return statements in catch and finally blocks.
  3. It is not possible to write return statements in catch blocks.
  4. It is not possible to write return statements in finally block.
Show Answer
Share Facebook gmail Twitter
7
How to re-throw an exception ?
  1. Using return keyword.
  2. Using throw keyword.
  3. Using re-throw keyword.
  4. None of the above.
Show Answer
Share Facebook gmail Twitter
8
How to re-throw a custom exception ?
  1. Using return keyword.
  2. Using throw keyword.
  3. Using rethrow keyword.
  4. None of the above.
Show Answer
Share Facebook gmail Twitter
9
How to create a custom exception or user defined exception in c# ?
  1. For creating a custom or user definded excption  the custom exception class must inherit from Exception class.
  2. For creating a custom or user defined exception the custom exception class must inherit from CustomException class.
  3. For creating a custom or user defined exception the custom exception class must inherit from UserDefinedException class.
  4. None of the above.
Show Answer
Share Facebook gmail Twitter
10
How to handle Array Index out of bounds exception in C# ?
  1. try
    {
       int[] num=new int[3]{19,20,89};
        for(int i=0;i<=num.Length;i++)
        {
          Console.WriteLine(num[i]);
        }
    }
    catch(ArrayIndexOutOfBoundsException ex)
    {
        //Write code for handling exception .
    }
  2. try
    {
       int[] num=new int[3]{19,20,89};
        for(int i=0;i<=num.Length;i++)
        {
          Console.WriteLine(num[i]);
        }
    }
    catch(Exception ex)
    {
        //Write code for handling exception .
    }
  3. Options 1 and 2 will work but option 1 is the best option.
  4. Options 1 and 2 will work but option 2 is the best option.
Show Answer
Share Facebook gmail Twitter
11
Which of the following class is the base class for all the Exceptions in C# ? 
  1. Exception.
  2. ApplicationException.
  3. SystemException.
  4. None of the above.
Show Answer
Share Facebook gmail Twitter
12
what is an innerException in c# ?
  1. InnerException will give the previous exception which was occurred in the program.
  2. InnerException will give the previous exception which caused the current exception.
  3. InnerException will give the exception details like method name and class name in which the current exception occurred.
  4. None of the above.
Show Answer
Share Facebook gmail Twitter
13
How many catch blocks can be written for a single try block ?
  1. One
  2. Two
  3. Many
  4. We can create many catch blocks but catch blocks order must from most specific exception to most generic exception (or) from super child catch block to super parent catch block. 
Show Answer
Share Facebook gmail Twitter
14
Identify the correct order of the catch blocks to make the program compile and execute ?
        try
        {
            int r = 90 / x;
        }
        catch (Exception ex)
        {

        }
        catch (ArithmeticException ex)
        {

        }
        catch (DivideByZeroException ex)
        {

        }
  1. First catch block must be present in the last place.
  2. First catch block must be present in last place and last catch block must be present in first place.
  3. Last catch block must be present in first place.
  4. None of the above .
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
16
What is the real use of handling exceptions in C# ?
  1. Exception handling will stop the abrupt termination of the program.
  2. Exception handling can be used for identifying the location of the code which is failing in the runtime by logging or storing the exceptions in error log files.
  3. Exception handling can be used for displaying the messages to the users, hence user can take corrective actions.
  4. All the three options are correct.
Show Answer
Share Facebook gmail Twitter
17
How to get a class name and method name in which exception is arising ?
  1. Use ex.TargetSite.DeclaringType.Name for getting class name and use ((System.Reflection.MemberInfo)(ex.TargetSite)).Name to get Method name.
  2. Use ex.ClassName and ex.MethodName to get class name and method name.
  3. Use ex.StackTrace.TypeName to get class name and use ex.StackTrace.Method name to get method name.
  4. None of the above.
Show Answer
Share Facebook gmail Twitter
18
How many finally blocks can be written for a single try block?
  1. Only one.
  2. Two
  3. More than one
  4. We can create a finally block for every catch block irrespective of number of try blocks.
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Read more papers :