Sail E0 Webinar

C++ Programming

ERROR HANDLING ALTERNATIVES MCQs

Total Questions : 10
Question 1.

What will happen when an exception is not processed?


  1.    It will eat up lot of memory and program size
  2.    Terminate the program
  3.    Crash the compiler
  4.    None of the mentioned
 Discuss Question
Answer: Option A. -> It will eat up lot of memory and program size

As in the case of not using an exception, it will remain useless in the program and increase 

the code complexity.


Question 2.

Pick out the correct statement for error handling alternatives.


  1.    Terminate the program
  2.    Use the stack
  3.    exit from the block
  4.    none of the mentioned
 Discuss Question
Answer: Option B. -> Use the stack

When an error is arised means, it will be pushed into stack and it can be corrected later by 

the programmer.


Question 3.

How many levels are there in exception safety?


  1.    1
  2.    2
  3.    3
  4.    4
 Discuss Question
Answer: Option C. -> 3

The three levels of exception safety are basic, strong and nothrow.


Question 4.

What is the use of RAII in c++ programing?


  1.    Improve the exception safety
  2.    Terminate the program
  3.    Exit from the block
  4.    None of the mentioned
 Discuss Question
Answer: Option A. -> Improve the exception safety

None.


Question 5.


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::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
  1.    256
  2.    invalid argument
  3.    Error
  4.    None of the mentioned
 Discuss Question
Answer: Option C. -> Error

We can't return a statement by using the return keyword, So it is arising an error.


Question 6.


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 << "n\Bad 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.
}
  1.    0
  2.    Bad operator
  3.    10
  4.    None of the mentioned
 Discuss Question
Answer: Option A. -> 0

We are dividing 0 and 10 in this program and we are using the throw statement in the function block.
Output:
$ g++ eal.cpp
$ a.out
0


Question 7.

What is most suitable for returning the logical errors in the program?


  1.    Use contructor and destructor
  2.    Set a global error indicator
  3.    Use break keyword
  4.    none of the mentioned
 Discuss Question
Answer: Option B. -> Set a global error indicator

None.


Question 8.


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
  1.    0
  2.    Bad operator
  3.    10
  4.    None of the mentioned
 Discuss Question
Answer: Option A. -> 0

Answer:a
Explanation:
We are checking the type id of char and float as they are not equal, We are printing c.
Output:
$ g++ eal.cpp
$ a.out
c
1A


Question 9.

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


  1.    You have to handle all exceptional cases explicitly
  2.    Your code size increases dramatically
  3.    The code becomes more difficult to read
  4.    All of the mentioned
 Discuss Question
Answer: Option D. -> All of the mentioned

As we are using return for each and every exception, It will definetly increase the code size.


Question 10.

Which alternative can replace the throw statement?


  1.    for
  2.    break
  3.    return
  4.    exit
 Discuss Question
Answer: Option C. -> return

throw and return does the same job like return a value. So it can be replaced.


Latest Videos

Latest Test Papers