Home / C# Programming / Exception Handling :: General Questions

C# Programming :: Exception Handling

  1. Which of the following statements are correct about exception handling in C#.NET?

    1. try blocks cannot be nested.
    2. In one function, there can be only one try block.
    3. An exception must be caught in the same function in which it is thrown.
    4. All values set up in the exception object are available in the catch block.
    5. While throwing a user-defined exception multiple values can be set in the exception, object.

  2. A.
    1 only
    B.
    1 and 2 only
    C.
    3 only
    D.
    4 and 5 only
    E.
    All of the above

    View Answer

    Workspace

    Discuss Discuss in Forum


  3. Exceptions can be thrown even from a constructor, whereas error codes cannot be returned from a constructor.

  4. A.
    True
    B.
    False

    View Answer

    Workspace

    Discuss Discuss in Forum


  5. Which of the following statements is correct about the C#.NET program given below if a value "6" is input to it?

     using System;
     namespace FresherGateConsoleApplication 
     { 
        class MyProgram   
        {     
            static void Main (string[] args)    
            {         
                 int index;       
                 int val = 66;         
                 int[] a = new int[5];       
                 try        
                 {        
                      Consote.Write("Enter a number: ");    
                      index = Convert.ToInt32(Console.ReadLine());                            
                      a [ index] = val;      
                 }        
                 catch(Exception e)       
                {           
                    Console.Write("Exception occurred ");        
                }          
                Console.Write("Remaining program ");       
            }     
        }
     }
    

     

     

  6. A.

    It will output: Exception occurred

    B.

    It will output: Remaining program

    C.

    It will output: Exception occurred Remaining program

    D.

    It will output: Remaining program Exception occurred

    E.

    The value 66 will get assigned to a[6].

    View Answer

    Workspace

    Discuss Discuss in Forum


  7. Which of the following statements is correct about the C#.NET program given below if a value "ABCD" is input to it?

    using System;
     namespace FresherGateConsoleApplication
     {    
         class MyProgram   
         {   
           static void Main(string[] args)           
           {         
               int index;        
               int val = 55;                
               int[] a = new int[5];              
               try         
               {                     
                  Console.Write("Enter a number: ");                 
                  index =Convert.ToInt32(Console.ReadLine());                
                  a[index] = val;      
               }    
               catch(FormatException e)      
               {           
                    Console.Write("Bad Format ");                 
               }           
               catch(IndexOutOfRangeException e)             
               {             
                    Console.Write("Index out of bounds ");             
               }            
               Console.Write("Remaining program ");   
          }  
       } 
    }
    

  8. A.

    It will output: Bad Format

    B.

    It will output: Remaining program

    C.

    It will output: Index out of bounds

    D.

    It will output: Bad Format Remaining program

    E.

    It will output: Index out of bounds Remaining program

    View Answer

    Workspace

    Discuss Discuss in Forum


  9. All code inside finally block is guaranteed to execute irrespective of whether an exception occurs in the protected block or not.

  10. A.
    True
    B.
    False

    View Answer

    Workspace

    Discuss Discuss in Forum


  11. Which of the following is NOT an Exception?

  12. A.
    StackOverflow
    B.
    Division By Zero
    C.
    Insufficient Memory
    D.
    Incorrect Arithmetic Expression
    E.
    Arithmetic overflow or underflow

    View Answer

    Workspace

    Discuss Discuss in Forum


  13. Which of the following statements is correct about the C#.NET program given below if a value "ABCD" is input to it?

     using System;
     namespace FresherGateConsoleApplication
      {     class MyProgram    
            {       
                static void Main(string[] args)      
                {             
                   int index;            
                   int vat = 88;    
                   int[] a = new int(5];        
                   try         
                   {             
                      Console.Write("Enter a number: ");                 
                      index = Convert.Toint32(Console.ReadLine());                 
                      a[index] = val;       
                   }       
                   catch(Exception e)     
                   {              
                      Console.Write("Exception occurred");               
                   }        
                   Console.Write("Remaining program");   
               }   
           } 
       }

     

  14. A.

    It will output: Exception occurred

    B.

    It will output: Remaining program

    C.

    It will output: Remaining program Exception occurred

    D.

    It will output: Exception occurred Remaining program

    E.

    The value 88 will get assigned to a[0].

    View Answer

    Workspace

    Discuss Discuss in Forum


  15. It is compulsory for all classes whose objects can be thrown with throw statement to be derived from System.Exception class.

  16. A.
    True
    B.
    False

    View Answer

    Workspace

    Discuss Discuss in Forum