Grouping of Exceptions C++ MCQ

Errorlogger
0
1. How many types of exception handling are there in c++?
a) 1
b) 2
c) 3
d) 4

Answer:b


2. How many runtime error messages associated with exception?
a) 2
b) 4
c) 5
d) infinite

Answer:c


3. Which block should be placed after try block?
a) catch
b) throw
c) a or b
d) none of the mentioned

Answer:c


4. What is the output of this program?
  1.     #include <iostream>
  2.     using namespace std;
  3.     int main()
  4.     {
  5.         double a = 10, b = 5, res;
  6.         char Operator = '/';
  7.         try 
  8.         {
  9.             if (b == 0)
  10.                 throw "Division by zero not allowed";
  11.             res = a / b;
  12.             cout << a << " / " << b << " = " << res;
  13.         }
  14.         catch(const char* Str)
  15.         {
  16.             cout << "\n Bad Operator: " << Str;
  17.         }
  18.         return 0;
  19.     }
a) 10
b) 2
c) Bad Operator
d) 10 / 5 = 2

Answer:d


5. What is the output of this program?
  1.     #include <iostream>
  2.     using namespace std;
  3.     int main()
  4.     {
  5.         try
  6.         {
  7.             throw 1;
  8.         }
  9.         catch (int a)
  10.         {
  11.             cout << "exception number:  " << a << endl;
  12.             return 0;
  13.         }
  14.         cout << "No exception " << endl;
  15.         return 0;
  16.     }
a) No exception
b) exception number
c) exception number: 1
d) none of the mentioned

Answer:c


6. What is the output of this program?
  1.     #include <iostream>
  2.     using namespace std;
  3.     int main()
  4.     {
  5.         int a = 10, b = 20, c = 30;
  6.         float  d;
  7.         try
  8.         {
  9.             if ((a - b) != 0)
  10.             {
  11.                 d = c / (a - b);
  12.                 cout << d;
  13.             }
  14.             else
  15.             {
  16.                 throw(a - b);
  17.             }
  18.         }
  19.         catch (int i)
  20.         {
  21.             cout<<"[expand title="View Answer"] Answer is infinite "<<i;
  22.         }
  23.     }
a) 10
b) -3
c) 15
d) none of the mentioned

Answer:b


7. What is the output of this program?
  1.     #include <iostream>
  2.     using namespace std;
  3.     void test(int x)
  4.     {
  5.         try
  6.         {
  7.             if (x > 0)
  8.                 throw x;
  9.             else
  10.                 throw 'x';
  11.         }
  12.         catch(int x)
  13.         {
  14.             cout<<"integer:"<<x;
  15.         }
  16.         catch(char x)
  17.         {
  18.             cout << "character:" << x;
  19.         }
  20.     }
  21.     int main()
  22.     {
  23.         test(10);
  24.         test(0);
  25.     }
a) integer:10character:x
b) integer:10
c) character:x
d) none of the mentioned

Answer:a


8. What is the output of this program?
  1.     #include <iostream>
  2.     using namespace std;
  3.     void PrintSequence(int StopNum)
  4.     {
  5.         int Num;
  6.         Num = 1;
  7.         while (true)
  8.         {
  9.             if (Num >= StopNum)
  10.                 throw Num;
  11.             cout << Num << endl;
  12.             Num++;
  13.         }
  14.     }
  15.     int main(void)
  16.     {
  17.         try
  18.         {
  19.             PrintSequence(2);
  20.         }
  21.         catch(int ExNum)
  22.         {
  23.             cout << "exception: " << ExNum << endl;
  24.         }
  25.         return 0;
  26.     }
a) 1
b) exception: 2
c) 1
exception: 2
d) none of the mentioned

Answer:c


9. Pick out the correct Answer.
a) Exceptions are not suitable for critical points in code.
b) Exception are suitable for critical points in code.
c) Both a & b
d) none of the mentioned

Answer:a


10. Where does the exceptions are used?
a) To preserve the program
b) Exceptions are used when postconditions of a function cannot be satisfied.
c) Exceptions are used when postconditions of a function can be satisfied.
d) none of the mentioned

Answer:c
Tags

Post a Comment

0Comments

Post a Comment (0)

#buttons=(Accept !) #days=(30)

Our website uses cookies to enhance your experience. Check Now
Accept !