C++ Programming Multiple Choice Questions - Exception Handling

This section focuses on the "Exception Handling" in C++ programming langauge. These Multiple Choice Questions (MCQ) should be practiced to improve the C++ programming skills required for various interviews (campus interview, walk-in interview, company interview), placement, entrance exam and other competitive examinations.

1. Which keyword is used to handle the expection?

A. Try
B. Throw
C. Catch
D. None of the above

View Answer


2. Which is used to throw a exception?

A. Try
B. Throw
C. Catch
D. None of the above

View Answer


3. Which exception is thrown by dynamic_cast?

A. bad_cast
B. bad_typeid
C. bad_exception
D. bad_alloc

View Answer


4. How do define the user-defined exceptions?

A. Inherting & overriding exception class functionlity
B. Overriding class functionlity
C. Inherting class functionlity
D. None of the above

View Answer


5. We can prevent a function from throwing any exceptions.

A. TRUE
B. FALSE
C. May Be
D. Can't Say

View Answer


6. In nested try block, if inner catch handler gets executed, then __________?

A. Program execution stops immediately.
B. Outer catch handler will also get executed.
C. Compiler will jump to the outer catch handler and then executes remaining executable statements of main().
D. Compiler will execute remaining executable statements of outer try block and then the main().

View Answer


7. Return type of uncaught_exception() is ___________.

A. int
B. bool
C. char *
D. double

View Answer


8. Which of the following statements are true about Catch handler? i) It must be placed immediately after try block T. ii) It can have multiple parameters. iii) There must be only one catch handler for every try block. iv) There can be multiple catch handler for a try block T. v) Generic catch handler can be placed anywhere after try block.

A. Only i, iv, v
B. Only i, ii, iii
C. Only i, iv
D. Only i, ii

View Answer


9. If inner catch handler is not able to handle the exception then__________ .

A. Compiler will look for outer try handler
B. Program terminates abnormally
C. Compiler will check for appropriate catch handler of outer try block
D. None of the above

View Answer


10. Which type of program is recommended to include in try block?

A. Static memory allocation
B. Dynamic memory allocation
C. Const reference
D. Pointer

View Answer


11. What is the output of this program?

#include <iostream>
using namespace std;

int main()
{
    try
    {
       throw 'b';
    }
    catch (int param)
    {
        cout << "Int Exception";
    }
    catch (...)
    {
        cout << "Default Exception";
    }
    cout << "After Exception";
    return 0;
}

A. Default Exception After Exception
B. Int Exception After Exception
C. Int Exception
D. Default Exception

View Answer


12. What is the output of this program?

#include <iostream>
using namespace std;

int main()
{
    try
    {
       throw 10;
    }
    catch (...)
    {
        cout << "Default Exceptionn";
    }
    catch (int param)
    {
        cout << "Int Exceptionn";
    }
    return 0;
}

A. Default Exception
B. Int Exception
C. Compiler Error
D. None of the above

View Answer


13. What is the output of this program?

#include <iostream>
using namespace std;

int main()
{
   int P = -1;
   try {
      cout << "Inside try";
      if (P < 0)
      {
         throw P;
         cout << "After throw";
      }
   }
   catch (int P ) {
      cout << "Exception Caught";
   }
   cout << "After catch";
   return 0;

}

A. Inside try Exception Caught After throw After catch
B. Inside try Exception Caught After catch
C. Inside try Exception Caught
D. Inside try After throw After catch

View Answer


14. What is the output of this program?

#include <iostream>
using namespace std;

class Base {};
class Derived: public Base {};

int main()
{
   Derived LFC;
   try {
       throw LFC;
   }
   catch(Base LFC) {
        cout<<"Base Exception";
   }
   catch(Derived LFC) {
        cout<<"Derived Exception";
   }
   return 0;
}

A. Derived Exception
B. Base Exception
C. Compiler Error
D. None of the above

View Answer


15. Which of the following is true about the following program

#include <iostream>
using namespace std;
int main () 
{
    try
    {
        throw 10;
    }
    catch (int LFC)
    {
        cout << "An exception occurred " << LFC << endl;
    }
    return 0;
}

A. 10
B. An exception
C. Error
D. An exception occurred 10

View Answer


16. What will be the output of this program?

#include <iostream>
using namespace std;

class myexception: public exception
{
    virtual const char* what() const throw()
    {
        return "My exception";
    }
} ex;

int main () 
{
    try
    {
        throw ex;
    }
    catch (exception& LFC)
    {
        cout << LFC.what() << endl;
    }
    return 0;
}

A. Exception
B. Error
C. My exception
D. runtime error

View Answer


17. What will be the output of this program?

#include <iostream>
using namespace std;

int main () 
{
    try
    {
        int* myarray = new int[1000];
        cout << "Allocated";
    }
    catch (exception& LFC)
    {
        cout << "Standard exception: " << LFC.what() << endl;
    }
    return 0;
} 

A. Allocated
B. Standard exception
C. Depends on the memory
D. Error

View Answer


18. What will be the output of the following program?

#include <iostream>
using namespace std;
int main( )
{
    try
    {
        string strg1("Test");
        string strg2("ing");
        strg1.append(strg2, 4, 2);
        cout << strg1 << endl;
    }
    catch (exception &LFC)
    {
        cout << "Caught: " << LFC.what() << endl;
        cout << "Type: " << typeid(LFC).name() << endl;
    };
    return 0;
}  

A. out of range
B. bad type_id
C. bad allocation
D. none of the mentioned

View Answer


19. Which illustrate predefined exceptions

A. Memory allocation error
B. I/O error
C. Both A and B
D. None of the above

View Answer


20. What is not called terminate() function in an constructor?

A. Main
B. Class
C. Destructor
D. None of the above

View Answer


21. Which statement is used to catch all types of exceptions?

A. Catch()
B. Catch(Test t)
C. Catch(...)
D. None of the above

View Answer


22. How to handle error in the destructor?

A. Throwing
B. Terminate
C. Both throwing & terminate
D. None of the above

View Answer


23. What kind of exceptions are available in c++?

A. Handled
B. Unhandled
C. Static
D. Dynamic

View Answer


24. Which of the following is true about exception handling in C++? i) There is a standard exception class like Exception class in Java. ii) All exceptions are unchecked in C++, i.e., compiler doesn't check if the exceptions are caught or not. iii) In C++, a function can specify the list of exceptions that it can throw using comma separated list like following.

A. Only i,iii
B. Only i,ii
C. Only ii,iii
D. All of the above

View Answer


25. What is the basic of grouping standard exception classes,in c++?

A. Catch
B. None of these
C. Error
D. Namespace std

View Answer


26. What is a count of standard exception?

A. 9
B. 5
C. 6
D. 7

View Answer


27. What should be included in try block in c++ programming language?

A. Static value
B. Dynamic allocation
C. None of the above
D. Const value

View Answer


28. How many standard exception exist in c++?

A. 9
B. 5
C. 6
D. 7

View Answer


29. Catch-all handlers uses which operators in c++?

A. String operators
B. Ternary operators
C. Ellipses operators
D. Unary operators

View Answer


30. Uncaught exception will call which function?

A. Terminate
B. Catch
C. None of the above
D. Throw

View Answer


31. Which operator in c++ programming language , is used by catch-all handler?

A. Ellipses operator
B. Ternary operator
C. String operator
D. Unary operator

View Answer


32. How to handle exception in constructor, in c++?

A. We have to return an exception
B. We have to throw an exception
C. Both A and B
D. None of the above

View Answer


33. How many parameter does the throw expression has, in c++?

A. 1
B. 2
C. 3
D. 4

View Answer





Also check :


Discussion


* You must be logged in to add comment.