MCQs
As in the case of not using an exception, it will remain useless in the program and increase
the code complexity.
When an error is arised means, it will be pushed into stack and it can be corrected later by
the programmer.
The three levels of exception safety are basic, strong and nothrow.
None.
We can't return a statement by using the return keyword, So it is arising an error.
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.
}
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
None.
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
As we are using return for each and every exception, It will definetly increase the code size.
throw and return does the same job like return a value. So it can be replaced.