CPP

CPP

Error Handling Alternatives has 10 Questions
Which alternative can replace the throw statement?

for
break
return
exit
What are the disadvantages if use return keyword to return error codes?

You have to handle all exceptional cases explicitly
Your code size increases dramatically
The code becomes more difficult to read
All of the mentioned
What is most suitable for returning the logical errors in the program?

Use contructor and destructor
Set a global error indicator
Use break keyword
none of the mentioned
What is the output of this program?
  1.     #include 
  2.     #include 
  3.     using namespace std;
  4.     class A 
  5.     { 
  6.     };
  7.     int main()
  8.     { 
  9.         char c; float x;
  10.         if (typeid(c) != typeid(x))
  11.         cout << typeid(c).name() << endl;
  12.         cout << typeid(A).name();
  13.         return 0;
  14.     }

c ???1A
x
Both a & b
None of the mentioned
What is the output of this program?
  1.     #include 
  2.     using namespace std;
  3.     void Division(const double a, const double b);
  4.     int main()
  5.     {
  6.         double op1=0, op2=10;
  7.         try 
  8.         {
  9.             Division(op1, op2);
  10.         }
  11.         catch (const char* Str)
  12.         {
  13.             cout << "\nBad Operator: " << Str;
  14.         }
  15.         return 0;
  16.     }
  17.     void Division(const double a, const double b)
  18.     {
  19.         double res;
  20.         if (b == 0)
  21.             throw "Division by zero not allowed";
  22.         res = a / b;
  23.         cout << res;
  24.     }

0
Bad operator
10
None of the mentioned
What is the output of this program?
  1.     #include 
  2.     #include 
  3.     #include 
  4.     using namespace std;
  5.     void MyFunc(char c)
  6.     {
  7.         if (c < numeric_limits<char>::max())
  8.             return invalid_argument;
  9.     }
  10.     int main()
  11.     {
  12.         try
  13.         {
  14.             MyFunc(256);
  15.         }
  16.         catch(invalid_argument& e)
  17.         {
  18.             cerr << e.what() << endl;
  19.             return -1;
  20.         }
  21.         return 0;
  22.     }

256
invalid argument
Error
None of the mentioned
What is the use of RAII in c++ programing?

Improve the exception safety
Terminate the program
Exit from the block
None of the mentioned
How many levels are there in exception safety?

1
2
3
4
Pick out the correct statement for error handling alternatives.

Terminate the program
Use the stack
exit from the block
none of the mentioned
What will happen when an exception is not processed?

It will eat up lot of memory and program size
Terminate the program
Crash the compiler
None of the mentioned