C++ Programming
ERROR HANDLING ALTERNATIVES MCQs
Total Questions : 10
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.
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
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.
Recent Questions
Q. DIVA:OPERA
Q. All Computers Must Have __________
Q. Which Of The Following Statements Are Correct With Regard To....
Q. (solve As Per The Direction Given Above)
Q. Deficiency Of 'Thiamine' Causes
Q. In Each Question Below A Sentence Broken Into Four Or Five P....
Q. IRS 1A And 1B Satellites Can Carry Which Of The Following Se....
Q. ....
Q. For A Dc Machine Shunt Resistance And Armature Resistance Va....
Q. ....
Q. Who Among The Following Was The First English Man To Visit W....
Q. Find The Correctly Spelt Word
Q. The Color Of Fluorine Is
Q. Rashi Went toy Shopping With Her Mother And Saw A Toy ....
Q. The Process Partially Responsible For The Life On Earth Is
Q. What Is The Place Of The Indian Men's Cricket Team In The La....
Q. ....
Q. Match The Following: 1. Nishka (i) Later Vedic Coi....
Q. Which Fertiliser Is Made (using Coke Oven Gas) In By Product....
Q. ....