CPP

CPP

Uncaught Exceptions has 9 Questions

What will happen when an exception is uncaught?

arise an error
program will run
exceute continuously
none of the mentioned
Which handler is used to handle all types of exception?

catch handler
catch-all handler
catch-none hendler
none of the mentioned
Which operator is used in catch-all handler?

ellipses operator
ternary operator
string operator
unary operator
What is the output of this program?
  1.     #include 
  2.     using namespace std;
  3.     class Base
  4.     {
  5.         protected:
  6.         int a;
  7.         public:
  8.         Base() 
  9.         { 
  10.             a = 34; 
  11.         }
  12.         Base(int i)
  13.         { 
  14.             a = i; 
  15.         }
  16.         virtual ~Base() 
  17.         { 
  18.             if (a < 0)  throw a; 
  19.         }
  20.         virtual int getA()
  21.         {
  22.             if (a < 0) 
  23.             { 
  24.                 throw a;
  25.             }
  26.         }
  27.     };
  28.     int main()
  29.     {
  30.         try
  31.         {
  32.             Base b(-25);
  33.             cout << endl << b.getA();
  34.         }
  35.         catch (int) 
  36.         {
  37.             cout << endl << "Illegal initialization";
  38.         }
  39.     }

Illegal initialization
terminate called after throwing an instance of 'int'
both a & b
none of the mentioned
What is the output of this program?
  1.     #include 
  2.     #include 
  3.     #include 
  4.     using namespace std;
  5.     void myterminate () 
  6.     {
  7.         cerr << "terminate handler called";
  8.         abort();
  9.     }
  10.     int main (void) 
  11.     {
  12.         set_terminate (myterminate);
  13.         throw 0; 
  14.         return 0;
  15.     }

terminate handler called
Aborted
both a & b
none of the mentioned
What is the output of this program?
  1.     #include 
  2.     using namespace std;
  3.     class Test1 
  4.     { 
  5.     };
  6.     class Test2 : public Test1 { };
  7.     void Funct();
  8.     int main()
  9.     {
  10.         try
  11.         {
  12.             Funct();
  13.         }
  14.         catch (const Test1&)
  15.         {
  16.             cerr << "Caught a exception" << endl;
  17.         }
  18.         return 0;
  19.     }
  20.     void Funct()
  21.     {
  22.         throw Test2();
  23.     }

Caught an exception
NULL
both a & b
none of the mentioned
What is the output of this program?
  1.     #include 
  2.     using namespace std;
  3.     #include 
  4.     #include 
  5.     void Funct()
  6.     {
  7.         cout << "Funct() was called by terminate()." << endl;
  8.         exit(0);
  9.     }
  10.     int main()
  11.     {
  12.         try
  13.         {
  14.             set_terminate(Funct);
  15.             throw "Out of memory!";
  16.         }
  17.         catch(int)
  18.         { 
  19.             cout << "Integer exception raised." << endl; 
  20.         }
  21.         return 0;
  22.     }

Integer exception raised.
Funct() was called by terminate().
both a & b
none of the mentioned
What will not be called when the terminate() is arised in constructor?

main()
class
destructor
none of the mentioned
What function will be called when we have a uncaught exception?

catch
throw
terminate
none of the mentioned