1. How many parameters does the throw expression can have?
a) 1
b) 2
c) 3
d) 4
2. Where does the exception are handled?
a) inside the program
b) outside the regular code
c) both a & b
d) none of the mentioned
3. Which is used to check the error in the block?
a) try
b) throw
c) catch
d) none of the mentioned
4. What is the output of this program?
a) exception arised
b) error
c) exception
d) runtime error
5. What is the output of this program?
a) 5
b) 10
c) 15
d) Positive Number Required
6. What is the output of this program?
a) 50
b) 0
c) Division by zero condition!
d) none of the mentioned
7. What is the output of this program?
a) 15
b) 5
c) 2
d) 1 is not a valid operator
8. What is the output of this program?
a) 5
b) 2.236
c) error
d) Cannot take sqrt of negative number
9. How to handle the exception in constructor?
a) We have to throw an exception
b) We have to return the exception
c) both a & b
d) none of the mentioned
10. What should present when throwing a object?
a) constructor
b) copy-constructor
c) destructor
d) none of the mentioned
a) 1
b) 2
c) 3
d) 4
Answer:a
2. Where does the exception are handled?
a) inside the program
b) outside the regular code
c) both a & b
d) none of the mentioned
Answer:b
3. Which is used to check the error in the block?
a) try
b) throw
c) catch
d) none of the mentioned
Answer:a
4. What is the output of this program?
#include <iostream>
#include <exception>
using namespace std;
class myexception: public exception
{
virtual const char* what() const throw()
{
return "exception arised";
}
} myex;
int main ()
{
try
{
throw myex;
}
catch (exception& e)
{
cout << e.what() << endl;
}
return 0;
}
b) error
c) exception
d) runtime error
Answer:a
5. What is the output of this program?
#include <iostream>
using namespace std;
int main()
{
int age=5;
try
{
if (age < 0)
throw "Positive Number Required";
cout << age << "\n\n";
}
catch(const char* Message)
{
cout << "Error: " << Message;
}
return 0;
}
b) 10
c) 15
d) Positive Number Required
Answer:a
6. What is the output of this program?
#include <iostream>
using namespace std;
double division(int a, int b)
{
if ( b == 0 )
{
throw "Division by zero condition!";
}
return (a / b);
}
int main ()
{
int x = 50;
int y = 0;
double z = 0;
try
{
z = division(x, y);
cout << z << endl;
}
catch (const char* msg)
{
cout << msg << endl;
}
return 0;
}
b) 0
c) Division by zero condition!
d) none of the mentioned
Answer:c
7. What is the output of this program?
#include <iostream>
#include <string>
using namespace std;
int main()
{
double Op1 = 10, Op2 = 5, Res;
char Op;
try
{
if (Op != '+' && Op != '-' && Op != '*' && Op != '/')
throw Op;
switch(Op)
{
case '+':
Res = Op1 + Op2;
break;
case '-':
Res = Op1 - Op2;
break;
case '*':
Res = Op1 * Op2;
break;
case '/':
Res = Op1 / Op2;
break;
}
cout << "\n" << Op1 << " " << Op << " "<< Op2 << " = " << Res;
}
catch (const char n)
{
cout << n << " is not a valid operator";
}
return 0;
}
b) 5
c) 2
d) 1 is not a valid operator
Answer:d
8. What is the output of this program?
#include<iostream>
#include "math.h"
using namespace std;
double MySqrt(double d)
{
if (d < 0.0)
throw "Cannot take sqrt of negative number";
return sqrt(d);
}
int main()
{
double d = 5;
cout << MySqrt(d) << endl;
}
b) 2.236
c) error
d) Cannot take sqrt of negative number
Answer:b
9. How to handle the exception in constructor?
a) We have to throw an exception
b) We have to return the exception
c) both a & b
d) none of the mentioned
Answer:a
10. What should present when throwing a object?
a) constructor
b) copy-constructor
c) destructor
d) none of the mentioned
Answer:b