• ( 1 ) Output of following program
      #include
      using namespace std;
      class Base {};
      class Derived: public Base {};
      int main()
      {
      Derived d;
      try {
      throw d;
      }
      catch(Base b) {
      cout<<"Caught Base Exception";
      }
      catch(Derived d) {
      cout<<"Caught Derived Exception";
      }
      return 0;
      }

    • 1) Caught Derived Exception
    • 2) Caught Base Exception
    • 3) Compiler Error
    • 4) None of these
    • Discussion in forum
      Answer : 2) Caught Base Exception
      Solution :








      discussion


      Answer : 2) Caught Base Exception

    • ( 2 ) What is the output of this program?
      #include
      using namespace std;
      int main()
      {
      try
      {
      throw 1;
      }
      catch (int a)
      {
      cout << "exception number: " << a << endl;
      return 0;
      }
      cout << "No exception " << endl;
      return 0;
      }

    • 1) No exception
    • 2) exception number
    • 3) exception number: 1
    • 4) None of these
    • Discussion in forum
      Answer : 3) exception number: 1
      Solution :








      discussion


      Answer : 3) exception number: 1

    • ( 3 ) In nested try block, if inner catch handler gets executed, then _____________ .

    • 1) Program execution stops immediately.
    • 2) Outer catch handler will also get executed.
    • 3) Compiler will jump to the outer catch handler and then executes remaining executable statements of main().
    • 4) Compiler will execute remaining executable statements of outer try block and then the main().
    • Discussion in forum
      Answer : 4) Compiler will execute remaining executable statements of outer try block and then the main().
      Solution :








      discussion


      Answer : 4) Compiler will execute remaining executable statements of outer try block and then the main().

    • ( 5 ) What is the output of this program?
      #include
      #include
      using namespace std;
      class Polymorphic {virtual void Member(){}};
      int main ()
      {
      try
      {
      Polymorphic * pb = 0;
      typeid(*pb);
      }
      catch (exception& e)
      {
      cerr << "exception caught: " << e.what() << endl;
      }
      return 0;
      }

    • 1) exception caught: std::bad_typeid
    • 2) exception caught: std::bad_alloc
    • 3) exception caught: std::bad_cast
    • 4) None of these
    • Discussion in forum
      Answer : 1) exception caught: std::bad_typeid
      Solution :








      discussion


      Answer : 1) exception caught: std::bad_typeid

    • ( 6 ) What is the output of this program?
      #include
      #include
      using namespace std;
      int main ()
      {
      int num = 3;
      string str_bad = "wrong number used";
      try
      {
      if ( num == 1 )
      {
      throw 5;
      }
      if ( num == 2 )
      {
      throw 1.1f;
      }
      if ( num != 1 || num != 2 )
      {
      throw str_bad;
      }
      }
      catch (int a)
      {
      cout << "Exception is: " << a << endl;
      }
      catch (float b)
      {
      cout << "Exception is: " << b << endl;
      }
      catch (...)
      {
      cout << str_bad << endl;
      }
      return 0;
      }

    • 1) Exception is 5
    • 2) Exception is 1.1f
    • 3) wrong number used
    • 4) None of these
    • Discussion in forum
      Answer : 3) wrong number used
      Solution :








      discussion


      Answer : 3) wrong number used

    • ( 8 ) Which of the following is true about exception handling in C++?
      1) There is a standard exception class like Exception class in Java.
      2) All exceptions are unchecked in C++, i.e., compiler doesn't check if the exceptions are caught or not.
      3) In C++, a function can specify the list of exceptions that it can throw using comma separated list like following.
      void fun(int a, char b) throw (Exception1, Exception2, ..)

    • 1) 1 and 3
    • 2) 1, 2 and 3
    • 3) 1 and 2
    • 4) 2 and 3
    • Discussion in forum
      Answer : 2) 1, 2 and 3
      Solution :








      discussion


      Answer : 2) 1, 2 and 3

    • ( 9 ) The process of handling the actual exception occurs _________

    • 1) inside the program
    • 2) outside the program
    • 3) Both 1 & 2
    • 4) None of these
    • Discussion in forum
      Answer : 2) outside the program
      Solution :








      discussion


      Answer : 2) outside the program

    • ( 10 ) C++ exception handling mechanism mainly uses how many keywords?

    • 1) Four
    • 2) Three
    • 3) Two
    • 4) None of these
    • Discussion in forum
      Answer : 2) Three
      Solution :








      discussion


      Answer : 2) Three





Top