1. How many types of exception handling are there in c++?
a) 1
b) 2
c) 3
d) 4
2. How many runtime error messages associated with exception?
a) 2
b) 4
c) 5
d) infinite
3. Which block should be placed after try block?
a) catch
b) throw
c) a or b
d) none of the mentioned
4. What is the output of this program?
a) 10
b) 2
c) Bad Operator
d) 10 / 5 = 2
5. What is the output of this program?
a) No exception
b) exception number
c) exception number: 1
d) none of the mentioned
6. What is the output of this program?
a) 10
b) -3
c) 15
d) none of the mentioned
7. What is the output of this program?
a) integer:10character:x
b) integer:10
c) character:x
d) none of the mentioned
8. What is the output of this program?
a) 1
b) exception: 2
c) 1
exception: 2
d) none of the mentioned
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
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
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?
#include <iostream>
using namespace std;
int main()
{
double a = 10, b = 5, res;
char Operator = '/';
try
{
if (b == 0)
throw "Division by zero not allowed";
res = a / b;
cout << a << " / " << b << " = " << res;
}
catch(const char* Str)
{
cout << "\n Bad Operator: " << Str;
}
return 0;
}
b) 2
c) Bad Operator
d) 10 / 5 = 2
Answer:d
5. What is the output of this program?
#include <iostream>
using namespace std;
int main()
{
try
{
throw 1;
}
catch (int a)
{
cout << "exception number: " << a << endl;
return 0;
}
cout << "No exception " << endl;
return 0;
}
b) exception number
c) exception number: 1
d) none of the mentioned
Answer:c
6. What is the output of this program?
#include <iostream>
using namespace std;
int main()
{
int a = 10, b = 20, c = 30;
float d;
try
{
if ((a - b) != 0)
{
d = c / (a - b);
cout << d;
}
else
{
throw(a - b);
}
}
catch (int i)
{
cout<<"[expand title="View Answer"] Answer is infinite "<<i;
}
}
b) -3
c) 15
d) none of the mentioned
Answer:b
7. What is the output of this program?
#include <iostream>
using namespace std;
void test(int x)
{
try
{
if (x > 0)
throw x;
else
throw 'x';
}
catch(int x)
{
cout<<"integer:"<<x;
}
catch(char x)
{
cout << "character:" << x;
}
}
int main()
{
test(10);
test(0);
}
b) integer:10
c) character:x
d) none of the mentioned
Answer:a
8. What is the output of this program?
#include <iostream>
using namespace std;
void PrintSequence(int StopNum)
{
int Num;
Num = 1;
while (true)
{
if (Num >= StopNum)
throw Num;
cout << Num << endl;
Num++;
}
}
int main(void)
{
try
{
PrintSequence(2);
}
catch(int ExNum)
{
cout << "exception: " << ExNum << endl;
}
return 0;
}
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